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
14
15#ifndef DOM_DOMSerializer_INCLUDED
16#define DOM_DOMSerializer_INCLUDED
17
18
19#include "Poco/XML/XML.h"
20#include "Poco/SAX/XMLReader.h"
21
22
23namespace Poco {
24namespace XML {
25
26
27class Node;
28class Element;
29class Text;
30class Comment;
31class ProcessingInstruction;
32class Entity;
33class CDATASection;
34class Notation;
35class Document;
36class DocumentType;
37class DocumentFragment;
38class DeclHandler;
39class LexicalHandler;
40
41
42class XML_API DOMSerializer: public XMLReader
43 /// The DOMSerializer serializes a DOM document
44 /// into a sequence of SAX events which are
45 /// reported to the registered SAX event
46 /// handlers.
47 ///
48 /// The DOMWriter uses a DOMSerializer with an
49 /// XMLWriter to serialize a DOM document into
50 /// textual XML.
51{
52public:
53 DOMSerializer();
54 /// Creates the DOMSerializer.
55
56 ~DOMSerializer();
57 /// Destroys the DOMSerializer.
58
59 void serialize(const Node* pNode);
60 /// Serializes a DOM node and its children
61 /// into a sequence of SAX events, which are
62 /// reported to the registered SAX event
63 /// handlers.
64
65 // XMLReader
66 void setEntityResolver(EntityResolver* pResolver);
67 EntityResolver* getEntityResolver() const;
68 void setDTDHandler(DTDHandler* pDTDHandler);
69 DTDHandler* getDTDHandler() const;
70 void setContentHandler(ContentHandler* pContentHandler);
71 ContentHandler* getContentHandler() const;
72 void setErrorHandler(ErrorHandler* pErrorHandler);
73 ErrorHandler* getErrorHandler() const;
74
75 void setFeature(const XMLString& featureId, bool state);
76 bool getFeature(const XMLString& featureId) const;
77 void setProperty(const XMLString& propertyId, const XMLString& value);
78 void setProperty(const XMLString& propertyId, void* value);
79 void* getProperty(const XMLString& propertyId) const;
80
81protected:
82 void parse(InputSource* pSource);
83 /// The DOMSerializer cannot parse an InputSource,
84 /// so this method simply throws an XMLException when invoked.
85
86 void parse(const XMLString& systemId);
87 /// The DOMSerializer cannot parse from a system identifier,
88 /// so this method simply throws an XMLException when invoked.
89
90 void parseMemoryNP(const char* xml, std::size_t size);
91 /// The DOMSerializer cannot parse from a system identifier,
92 /// so this method simply throws an XMLException when invoked.
93
94 void iterate(const Node* pNode) const;
95 void handleNode(const Node* pNode) const;
96 void handleElement(const Element* pElement) const;
97 void handleCharacterData(const Text* pText) const;
98 void handleComment(const Comment* pComment) const;
99 void handlePI(const ProcessingInstruction* pPI) const;
100 void handleCDATASection(const CDATASection* pCDATA) const;
101 void handleDocument(const Document* pDocument) const;
102 void handleDocumentType(const DocumentType* pDocumentType) const;
103 void handleFragment(const DocumentFragment* pFragment) const;
104 void handleNotation(const Notation* pNotation) const;
105 void handleEntity(const Entity* pEntity) const;
106
107private:
108 EntityResolver* _pEntityResolver;
109 DTDHandler* _pDTDHandler;
110 ContentHandler* _pContentHandler;
111 ErrorHandler* _pErrorHandler;
112 DeclHandler* _pDeclHandler;
113 LexicalHandler* _pLexicalHandler;
114
115 static const XMLString CDATA;
116};
117
118
119} } // namespace Poco::XML
120
121
122#endif // DOM_DOMSerializer_INCLUDED
123