diff options
Diffstat (limited to '')
-rw-r--r-- | src/xmlwriter.h | 100 |
1 files changed, 87 insertions, 13 deletions
diff --git a/src/xmlwriter.h b/src/xmlwriter.h index 796d6fb..c48e810 100644 --- a/src/xmlwriter.h +++ b/src/xmlwriter.h | |||
@@ -1,22 +1,96 @@ | |||
1 | #ifndef XML_WRITER_H | 1 | #ifndef XMLWRITER |
2 | #define XML_WRITER_H | 2 | #define XMLWRITER |
3 | 3 | ||
4 | #include <stdint.h> | 4 | #include "xmlnode.h" |
5 | #include "xmldocument.h" | ||
5 | 6 | ||
6 | namespace Bu | 7 | /** |
8 | * Implements xml writing in the XML standard format. Also allows you to | ||
9 | * break that format and auto-indent your exported xml data for ease of | ||
10 | * reading. The auto-indenting will only be applied to sections that | ||
11 | * have no content of their own already. This means that except for | ||
12 | * whitespace all of your data will be preserved perfectly. | ||
13 | * You can create an XmlWriter object around a file, or access the static | ||
14 | * write function directly and just hand it a filename and a root XmlNode. | ||
15 | * When using an XmlWriter object the interface is identicle to that of | ||
16 | * the XmlDocument class, so reference that class for API info. However | ||
17 | * when the initial (or root) node is closed, and the document is finished | ||
18 | * the file will be created and written to automatically. The user can | ||
19 | * check to see if this is actually true by calling the isFinished | ||
20 | * function in the XmlDocument class. | ||
21 | *@author Mike Buland | ||
22 | */ | ||
23 | class XmlWriter : public XmlDocument | ||
7 | { | 24 | { |
25 | public: | ||
8 | /** | 26 | /** |
9 | * | 27 | * Construct a standard XmlWriter. |
28 | *@param sIndent Set this to something other than NULL to include it as an | ||
29 | * indent before each node in the output that doesn't already have content. | ||
30 | * If you are using the whitespace stripping option in the XmlReader and set | ||
31 | * this to a tab or some spaces it will never effect the content of your | ||
32 | * file. | ||
10 | */ | 33 | */ |
11 | class XmlWriter | 34 | XmlWriter( const char *sIndent=NULL, XmlNode *pRoot=NULL ); |
12 | { | ||
13 | public: | ||
14 | XmlWriter(); | ||
15 | virtual ~XmlWriter(); | ||
16 | 35 | ||
17 | private: | 36 | /** |
37 | * Destroy the writer. | ||
38 | */ | ||
39 | virtual ~XmlWriter(); | ||
40 | |||
41 | /** | ||
42 | * This override of the parent class closeNode function calls the parent | ||
43 | * class, but also triggers a write operation when the final node is closed. | ||
44 | * This means that by checking the isCompleted() function the user may also | ||
45 | * check to see if their file has been written or not. | ||
46 | */ | ||
47 | void closeNode(); | ||
48 | |||
49 | void write(); | ||
18 | 50 | ||
19 | }; | 51 | private: |
20 | } | 52 | std::string sIndent; /**< The indent string */ |
53 | |||
54 | std::string escape( std::string sIn ); | ||
55 | |||
56 | /** | ||
57 | * Write the file. | ||
58 | *@param pNode The root node | ||
59 | *@param sIndent The indent text. | ||
60 | */ | ||
61 | void write( XmlNode *pNode, const char *sIndent=NULL ); | ||
62 | |||
63 | /** | ||
64 | * Write a node in the file, including children. | ||
65 | *@param pNode The node to write. | ||
66 | *@param nIndent The indent level (the number of times to include sIndent) | ||
67 | *@param sIndent The indent text. | ||
68 | */ | ||
69 | void writeNode( XmlNode *pNode, int nIndent, const char *sIndent ); | ||
70 | |||
71 | /** | ||
72 | * Write the properties of a node. | ||
73 | *@param pNode The node who's properties to write. | ||
74 | *@param nIndent The indent level of the containing node | ||
75 | *@param sIndent The indent text. | ||
76 | */ | ||
77 | void writeNodeProps( XmlNode *pNode, int nIndent, const char *sIndent ); | ||
78 | |||
79 | /** | ||
80 | * Called to write the actual indent. | ||
81 | *@param nIndent The indent level. | ||
82 | *@param sIndent The indent text. | ||
83 | */ | ||
84 | void writeIndent( int nIndent, const char *sIndent ); | ||
85 | |||
86 | /** | ||
87 | * This is the function that must be overridden in order to use this class. | ||
88 | * It must write the null-terminated string sString, minus the mull, | ||
89 | * verbatum to it's output device. Adding extra characters for any reason | ||
90 | * will break the XML formatting. | ||
91 | *@param sString The string data to write to the output. | ||
92 | */ | ||
93 | virtual void writeString( const char *sString ) = 0; | ||
94 | }; | ||
21 | 95 | ||
22 | #endif | 96 | #endif |