DOMSerializer.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // DOMSerializer.h
  3. //
  4. // Library: XML
  5. // Package: DOM
  6. // Module: DOMSerializer
  7. //
  8. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  9. // and Contributors.
  10. //
  11. // SPDX-License-Identifier: BSL-1.0
  12. //
  13. #ifndef DOM_DOMSerializer_INCLUDED
  14. #define DOM_DOMSerializer_INCLUDED
  15. #include "Poco/XML/XML.h"
  16. #include "Poco/SAX/XMLReader.h"
  17. namespace Poco {
  18. namespace XML {
  19. class Node;
  20. class Element;
  21. class Text;
  22. class Comment;
  23. class ProcessingInstruction;
  24. class Entity;
  25. class CDATASection;
  26. class Notation;
  27. class Document;
  28. class DocumentType;
  29. class DocumentFragment;
  30. class DeclHandler;
  31. class LexicalHandler;
  32. class XML_API DOMSerializer: public XMLReader
  33. /// The DOMSerializer serializes a DOM document
  34. /// into a sequence of SAX events which are
  35. /// reported to the registered SAX event
  36. /// handlers.
  37. ///
  38. /// The DOMWriter uses a DOMSerializer with an
  39. /// XMLWriter to serialize a DOM document into
  40. /// textual XML.
  41. {
  42. public:
  43. DOMSerializer();
  44. /// Creates the DOMSerializer.
  45. ~DOMSerializer();
  46. /// Destroys the DOMSerializer.
  47. void serialize(const Node* pNode);
  48. /// Serializes a DOM node and its children
  49. /// into a sequence of SAX events, which are
  50. /// reported to the registered SAX event
  51. /// handlers.
  52. // XMLReader
  53. void setEntityResolver(EntityResolver* pResolver);
  54. EntityResolver* getEntityResolver() const;
  55. void setDTDHandler(DTDHandler* pDTDHandler);
  56. DTDHandler* getDTDHandler() const;
  57. void setContentHandler(ContentHandler* pContentHandler);
  58. ContentHandler* getContentHandler() const;
  59. void setErrorHandler(ErrorHandler* pErrorHandler);
  60. ErrorHandler* getErrorHandler() const;
  61. void setFeature(const XMLString& featureId, bool state);
  62. bool getFeature(const XMLString& featureId) const;
  63. void setProperty(const XMLString& propertyId, const XMLString& value);
  64. void setProperty(const XMLString& propertyId, void* value);
  65. void* getProperty(const XMLString& propertyId) const;
  66. protected:
  67. void parse(InputSource* pSource);
  68. /// The DOMSerializer cannot parse an InputSource,
  69. /// so this method simply throws an XMLException when invoked.
  70. void parse(const XMLString& systemId);
  71. /// The DOMSerializer cannot parse from a system identifier,
  72. /// so this method simply throws an XMLException when invoked.
  73. void parseMemoryNP(const char* xml, std::size_t size);
  74. /// The DOMSerializer cannot parse from a system identifier,
  75. /// so this method simply throws an XMLException when invoked.
  76. void iterate(const Node* pNode) const;
  77. void handleNode(const Node* pNode) const;
  78. void handleElement(const Element* pElement) const;
  79. void handleCharacterData(const Text* pText) const;
  80. void handleComment(const Comment* pComment) const;
  81. void handlePI(const ProcessingInstruction* pPI) const;
  82. void handleCDATASection(const CDATASection* pCDATA) const;
  83. void handleDocument(const Document* pDocument) const;
  84. void handleDocumentType(const DocumentType* pDocumentType) const;
  85. void handleFragment(const DocumentFragment* pFragment) const;
  86. void handleNotation(const Notation* pNotation) const;
  87. void handleEntity(const Entity* pEntity) const;
  88. private:
  89. EntityResolver* _pEntityResolver;
  90. DTDHandler* _pDTDHandler;
  91. ContentHandler* _pContentHandler;
  92. ErrorHandler* _pErrorHandler;
  93. DeclHandler* _pDeclHandler;
  94. LexicalHandler* _pLexicalHandler;
  95. static const XMLString CDATA;
  96. };
  97. } } // namespace Poco::XML
  98. #endif // DOM_DOMSerializer_INCLUDED