1 | // |
2 | // DOMBuilder.h |
3 | // |
4 | // Library: XML |
5 | // Package: DOM |
6 | // Module: DOMBuilder |
7 | // |
8 | // Definition of the DOMBuilder class. |
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 DOM_DOMBuilder_INCLUDED |
18 | #define DOM_DOMBuilder_INCLUDED |
19 | |
20 | |
21 | #include "Poco/XML/XML.h" |
22 | #include "Poco/SAX/ContentHandler.h" |
23 | #include "Poco/SAX/LexicalHandler.h" |
24 | #include "Poco/SAX/DTDHandler.h" |
25 | #include "Poco/XML/XMLString.h" |
26 | |
27 | |
28 | namespace Poco { |
29 | namespace XML { |
30 | |
31 | |
32 | class XMLReader; |
33 | class Document; |
34 | class InputSource; |
35 | class AbstractNode; |
36 | class AbstractContainerNode; |
37 | class NamePool; |
38 | |
39 | |
40 | class XML_API DOMBuilder: protected DTDHandler, protected ContentHandler, protected LexicalHandler |
41 | /// This class builds a tree representation of an |
42 | /// XML document, according to the W3C Document Object Model, Level 1 and 2 |
43 | /// specifications. |
44 | /// |
45 | /// The actual XML parsing is done by an XMLReader, which |
46 | /// must be supplied to the DOMBuilder. |
47 | { |
48 | public: |
49 | DOMBuilder(XMLReader& xmlReader, NamePool* pNamePool = 0); |
50 | /// Creates a DOMBuilder using the given XMLReader. |
51 | /// If a NamePool is given, it becomes the Document's NamePool. |
52 | |
53 | virtual ~DOMBuilder(); |
54 | /// Destroys the DOMBuilder. |
55 | |
56 | virtual Document* parse(const XMLString& uri); |
57 | /// Parse an XML document from a location identified by an URI. |
58 | |
59 | virtual Document* parse(InputSource* pInputSource); |
60 | /// Parse an XML document from a location identified by an InputSource. |
61 | |
62 | virtual Document* parseMemoryNP(const char* xml, std::size_t size); |
63 | /// Parses an XML document from memory. |
64 | |
65 | protected: |
66 | // DTDHandler |
67 | void notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId); |
68 | void unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName); |
69 | |
70 | // ContentHandler |
71 | void setDocumentLocator(const Locator* loc); |
72 | void startDocument(); |
73 | void endDocument(); |
74 | void startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attributes); |
75 | void endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname); |
76 | void characters(const XMLChar ch[], int start, int length); |
77 | void ignorableWhitespace(const XMLChar ch[], int start, int length); |
78 | void processingInstruction(const XMLString& target, const XMLString& data); |
79 | void startPrefixMapping(const XMLString& prefix, const XMLString& uri); |
80 | void endPrefixMapping(const XMLString& prefix); |
81 | void skippedEntity(const XMLString& name); |
82 | |
83 | // LexicalHandler |
84 | void startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId); |
85 | void endDTD(); |
86 | void startEntity(const XMLString& name); |
87 | void endEntity(const XMLString& name); |
88 | void startCDATA(); |
89 | void endCDATA(); |
90 | void (const XMLChar ch[], int start, int length); |
91 | |
92 | void appendNode(AbstractNode* pNode); |
93 | |
94 | void setupParse(); |
95 | |
96 | private: |
97 | static const XMLString EMPTY_STRING; |
98 | |
99 | XMLReader& _xmlReader; |
100 | NamePool* _pNamePool; |
101 | Document* _pDocument; |
102 | AbstractContainerNode* _pParent; |
103 | AbstractNode* _pPrevious; |
104 | bool _inCDATA; |
105 | bool _namespaces; |
106 | }; |
107 | |
108 | |
109 | } } // namespace Poco::XML |
110 | |
111 | |
112 | #endif // DOM_DOMBuilder_INCLUDED |
113 | |