DOMBuilder.h 3.2 KB

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