| 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 | |
| 16 | |
| 17 | #ifndef SAX_SAXParser_INCLUDED | 
| 18 | #define SAX_SAXParser_INCLUDED | 
| 19 | |
| 20 | |
| 21 | #include "Poco/XML/XML.h" | 
| 22 | #include "Poco/SAX/XMLReader.h" | 
| 23 | #include "Poco/XML/ParserEngine.h" | 
| 24 | |
| 25 | |
| 26 | namespace Poco { | 
| 27 | namespace XML { | 
| 28 | |
| 29 | |
| 30 | class XML_API SAXParser: public XMLReader | 
| 31 | /// This class provides a SAX2 (Simple API for XML) interface to expat, | 
| 32 | /// the XML parser toolkit. | 
| 33 | /// The following SAX2 features and properties are supported: | 
| 34 | /// * http://xml.org/sax/features/external-general-entities | 
| 35 | /// * http://xml.org/sax/features/external-parameter-entities | 
| 36 | /// * http://xml.org/sax/features/namespaces | 
| 37 | /// * http://xml.org/sax/features/namespace-prefixes | 
| 38 | /// * http://xml.org/sax/properties/lexical-handler | 
| 39 | /// * http://xml.org/sax/properties/declaration-handler | 
| 40 | /// | 
| 41 | /// The following proprietary extensions are supported: | 
| 42 | /// * http://www.appinf.com/features/enable-partial-reads -- | 
| 43 | /// see ParserEngine::setEnablePartialReads() | 
| 44 | { | 
| 45 | public: | 
| 46 | SAXParser(); | 
| 47 | /// Creates an SAXParser. | 
| 48 | |
| 49 | SAXParser(const XMLString& encoding); | 
| 50 | /// Creates an SAXParser with the given encoding. | 
| 51 | |
| 52 | ~SAXParser(); | 
| 53 | /// Destroys the SAXParser. | 
| 54 | |
| 55 | void setEncoding(const XMLString& encoding); | 
| 56 | /// Sets the encoding used by the parser if no | 
| 57 | /// encoding is specified in the XML document. | 
| 58 | |
| 59 | const XMLString& getEncoding() const; | 
| 60 | /// Returns the name of the encoding used by | 
| 61 | /// the parser if no encoding is specified in | 
| 62 | /// the XML document. | 
| 63 | |
| 64 | void addEncoding(const XMLString& name, Poco::TextEncoding* pEncoding); | 
| 65 | /// Adds an encoding to the parser. Does not take ownership of the pointer! | 
| 66 | |
| 67 | /// XMLReader | 
| 68 | void setEntityResolver(EntityResolver* pResolver); | 
| 69 | EntityResolver* getEntityResolver() const; | 
| 70 | void setDTDHandler(DTDHandler* pDTDHandler); | 
| 71 | DTDHandler* getDTDHandler() const; | 
| 72 | void setContentHandler(ContentHandler* pContentHandler); | 
| 73 | ContentHandler* getContentHandler() const; | 
| 74 | void setErrorHandler(ErrorHandler* pErrorHandler); | 
| 75 | ErrorHandler* getErrorHandler() const; | 
| 76 | void setFeature(const XMLString& featureId, bool state); | 
| 77 | bool getFeature(const XMLString& featureId) const; | 
| 78 | void setProperty(const XMLString& propertyId, const XMLString& value); | 
| 79 | void setProperty(const XMLString& propertyId, void* value); | 
| 80 | void* getProperty(const XMLString& propertyId) const; | 
| 81 | void parse(InputSource* pSource); | 
| 82 | void parse(const XMLString& systemId); | 
| 83 | void parseMemoryNP(const char* xml, std::size_t size); | 
| 84 | |
| 85 | /// Extensions | 
| 86 | void parseString(const std::string& xml); | 
| 87 | |
| 88 | static const XMLString FEATURE_PARTIAL_READS; | 
| 89 | |
| 90 | protected: | 
| 91 | void setupParse(); | 
| 92 | |
| 93 | private: | 
| 94 | ParserEngine _engine; | 
| 95 | bool _namespaces; | 
| 96 | bool _namespacePrefixes; | 
| 97 | }; | 
| 98 | |
| 99 | |
| 100 | } } // namespace Poco::XML | 
| 101 | |
| 102 | |
| 103 | #endif // SAX_SAXParser_INCLUDED | 
| 104 | 
