1 | // |
2 | // DOMWriter.h |
3 | // |
4 | // Library: XML |
5 | // Package: DOM |
6 | // Module: DOMWriter |
7 | // |
8 | // Definition of class DOMWriter. |
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_DOMWriter_INCLUDED |
18 | #define DOM_DOMWriter_INCLUDED |
19 | |
20 | |
21 | #include "Poco/XML/XML.h" |
22 | #include "Poco/XML/XMLString.h" |
23 | #include "Poco/XML/XMLStream.h" |
24 | #include "Poco/TextEncoding.h" |
25 | |
26 | |
27 | namespace Poco { |
28 | namespace XML { |
29 | |
30 | |
31 | class Node; |
32 | class Document; |
33 | |
34 | |
35 | class XML_API DOMWriter |
36 | /// The DOMWriter uses a DOMSerializer with an |
37 | /// XMLWriter to serialize a DOM document into |
38 | /// textual XML. |
39 | { |
40 | public: |
41 | DOMWriter(); |
42 | /// Creates a DOMWriter. |
43 | |
44 | ~DOMWriter(); |
45 | /// Destroys a DOMWriter. |
46 | |
47 | void setEncoding(const std::string& encodingName, Poco::TextEncoding& textEncoding); |
48 | /// Sets the encoding, which will be reflected in the written XML declaration. |
49 | |
50 | const std::string& getEncoding() const; |
51 | /// Returns the encoding name set with setEncoding. |
52 | |
53 | void setOptions(int options); |
54 | /// Sets options for the internal XMLWriter. |
55 | /// |
56 | /// See class XMLWriter for available options. |
57 | |
58 | int getOptions() const; |
59 | /// Returns the options for the internal XMLWriter. |
60 | |
61 | void setNewLine(const std::string& newLine); |
62 | /// Sets the line ending characters for the internal |
63 | /// XMLWriter. See XMLWriter::setNewLine() for a list |
64 | /// of supported values. |
65 | |
66 | const std::string& getNewLine() const; |
67 | /// Returns the line ending characters used by the |
68 | /// internal XMLWriter. |
69 | |
70 | void setIndent(const std::string& indent); |
71 | /// Sets the string used for one indentation step. |
72 | /// |
73 | /// The default is a single TAB character. |
74 | /// The given string should only contain TAB or SPACE |
75 | /// characters (e.g., a single TAB character, or |
76 | /// two to four SPACE characters). |
77 | |
78 | const std::string& getIndent() const; |
79 | /// Returns the string used for one indentation step. |
80 | |
81 | void writeNode(XMLByteOutputStream& ostr, const Node* pNode); |
82 | /// Writes the XML for the given node to the specified stream. |
83 | |
84 | void writeNode(const std::string& systemId, const Node* pNode); |
85 | /// Writes the XML for the given node to the file specified in systemId, |
86 | /// using a standard file output stream (Poco::FileOutputStream). |
87 | |
88 | private: |
89 | std::string _encodingName; |
90 | Poco::TextEncoding* _pTextEncoding; |
91 | int _options; |
92 | std::string _newLine; |
93 | std::string _indent; |
94 | }; |
95 | |
96 | |
97 | // |
98 | // inlines |
99 | // |
100 | inline const std::string& DOMWriter::getEncoding() const |
101 | { |
102 | return _encodingName; |
103 | } |
104 | |
105 | |
106 | inline int DOMWriter::getOptions() const |
107 | { |
108 | return _options; |
109 | } |
110 | |
111 | |
112 | inline const std::string& DOMWriter::getNewLine() const |
113 | { |
114 | return _newLine; |
115 | } |
116 | |
117 | |
118 | inline const std::string& DOMWriter::getIndent() const |
119 | { |
120 | return _indent; |
121 | } |
122 | |
123 | |
124 | } } // namespace Poco::XML |
125 | |
126 | |
127 | #endif // DOM_DOMWriter_INCLUDED |
128 | |