SAXParser.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // SAXParser.h
  3. //
  4. // Library: XML
  5. // Package: SAX
  6. // Module: SAX
  7. //
  8. // Implementation of the XMLReader interface.
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef SAX_SAXParser_INCLUDED
  16. #define SAX_SAXParser_INCLUDED
  17. #include "Poco/XML/XML.h"
  18. #include "Poco/SAX/XMLReader.h"
  19. #include "Poco/XML/ParserEngine.h"
  20. namespace Poco {
  21. namespace XML {
  22. class XML_API SAXParser: public XMLReader
  23. /// This class provides a SAX2 (Simple API for XML) interface to expat,
  24. /// the XML parser toolkit.
  25. /// The following SAX2 features and properties are supported:
  26. /// * http://xml.org/sax/features/external-general-entities
  27. /// * http://xml.org/sax/features/external-parameter-entities
  28. /// * http://xml.org/sax/features/namespaces
  29. /// * http://xml.org/sax/features/namespace-prefixes
  30. /// * http://xml.org/sax/properties/lexical-handler
  31. /// * http://xml.org/sax/properties/declaration-handler
  32. ///
  33. /// The following proprietary extensions are supported:
  34. /// * http://www.appinf.com/features/enable-partial-reads --
  35. /// see ParserEngine::setEnablePartialReads()
  36. {
  37. public:
  38. SAXParser();
  39. /// Creates an SAXParser.
  40. SAXParser(const XMLString& encoding);
  41. /// Creates an SAXParser with the given encoding.
  42. ~SAXParser();
  43. /// Destroys the SAXParser.
  44. void setEncoding(const XMLString& encoding);
  45. /// Sets the encoding used by the parser if no
  46. /// encoding is specified in the XML document.
  47. const XMLString& getEncoding() const;
  48. /// Returns the name of the encoding used by
  49. /// the parser if no encoding is specified in
  50. /// the XML document.
  51. void addEncoding(const XMLString& name, Poco::TextEncoding* pEncoding);
  52. /// Adds an encoding to the parser. Does not take ownership of the pointer!
  53. /// XMLReader
  54. void setEntityResolver(EntityResolver* pResolver);
  55. EntityResolver* getEntityResolver() const;
  56. void setDTDHandler(DTDHandler* pDTDHandler);
  57. DTDHandler* getDTDHandler() const;
  58. void setContentHandler(ContentHandler* pContentHandler);
  59. ContentHandler* getContentHandler() const;
  60. void setErrorHandler(ErrorHandler* pErrorHandler);
  61. ErrorHandler* getErrorHandler() const;
  62. void setFeature(const XMLString& featureId, bool state);
  63. bool getFeature(const XMLString& featureId) const;
  64. void setProperty(const XMLString& propertyId, const XMLString& value);
  65. void setProperty(const XMLString& propertyId, void* value);
  66. void* getProperty(const XMLString& propertyId) const;
  67. void parse(InputSource* pSource);
  68. void parse(const XMLString& systemId);
  69. void parseMemoryNP(const char* xml, std::size_t size);
  70. /// Extensions
  71. void parseString(const std::string& xml);
  72. static const XMLString FEATURE_PARTIAL_READS;
  73. protected:
  74. void setupParse();
  75. private:
  76. ParserEngine _engine;
  77. bool _namespaces;
  78. bool _namespacePrefixes;
  79. };
  80. } } // namespace Poco::XML
  81. #endif // SAX_SAXParser_INCLUDED