diff options
Diffstat (limited to 'src/xmldocument.cpp')
-rw-r--r-- | src/xmldocument.cpp | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/src/xmldocument.cpp b/src/xmldocument.cpp new file mode 100644 index 0000000..234ff81 --- /dev/null +++ b/src/xmldocument.cpp | |||
@@ -0,0 +1,142 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include "xmlwriter.h" | ||
4 | |||
5 | XmlDocument::XmlDocument( XmlNode *pRoot ) | ||
6 | { | ||
7 | this->pRoot = pRoot; | ||
8 | pCurrent = NULL; | ||
9 | bCompleted = (pRoot!=NULL); | ||
10 | } | ||
11 | |||
12 | XmlDocument::~XmlDocument() | ||
13 | { | ||
14 | if( pRoot ) | ||
15 | { | ||
16 | delete pRoot; | ||
17 | } | ||
18 | } | ||
19 | |||
20 | void XmlDocument::addNode( const char *sName, const char *sContent, bool bClose ) | ||
21 | { | ||
22 | if( pRoot == NULL ) | ||
23 | { | ||
24 | // This is the first node, so ignore position and just insert it. | ||
25 | pCurrent = pRoot = new XmlNode( sName, NULL, sContent ); | ||
26 | } | ||
27 | else | ||
28 | { | ||
29 | pCurrent = pCurrent->addChild( sName, sContent ); | ||
30 | } | ||
31 | |||
32 | if( bClose ) | ||
33 | { | ||
34 | closeNode(); | ||
35 | } | ||
36 | } | ||
37 | |||
38 | void XmlDocument::setName( const char *sName ) | ||
39 | { | ||
40 | pCurrent->setName( sName ); | ||
41 | } | ||
42 | |||
43 | bool XmlDocument::isCompleted() | ||
44 | { | ||
45 | return bCompleted; | ||
46 | } | ||
47 | |||
48 | XmlNode *XmlDocument::getRoot() | ||
49 | { | ||
50 | return pRoot; | ||
51 | } | ||
52 | |||
53 | XmlNode *XmlDocument::getCurrent() | ||
54 | { | ||
55 | return pCurrent; | ||
56 | } | ||
57 | |||
58 | void XmlDocument::closeNode() | ||
59 | { | ||
60 | if( pCurrent != NULL ) | ||
61 | { | ||
62 | pCurrent = pCurrent->getParent(); | ||
63 | |||
64 | if( pCurrent == NULL ) | ||
65 | { | ||
66 | bCompleted = true; | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | |||
71 | void XmlDocument::addProperty( const char *sName, const char *sValue ) | ||
72 | { | ||
73 | if( pCurrent ) | ||
74 | { | ||
75 | pCurrent->addProperty( sName, sValue ); | ||
76 | } | ||
77 | } | ||
78 | |||
79 | void XmlDocument::addProperty( const char *sName, const unsigned char nValue ) | ||
80 | { | ||
81 | char buf[12]; | ||
82 | sprintf( buf, "%hhi", nValue ); | ||
83 | addProperty( sName, buf ); | ||
84 | } | ||
85 | |||
86 | void XmlDocument::addProperty( const char *sName, const char nValue ) | ||
87 | { | ||
88 | char buf[12]; | ||
89 | sprintf( buf, "%hhi", nValue ); | ||
90 | addProperty( sName, buf ); | ||
91 | } | ||
92 | |||
93 | void XmlDocument::addProperty( const char *sName, const unsigned short nValue ) | ||
94 | { | ||
95 | char buf[12]; | ||
96 | sprintf( buf, "%hi", nValue ); | ||
97 | addProperty( sName, buf ); | ||
98 | } | ||
99 | |||
100 | void XmlDocument::addProperty( const char *sName, const short nValue ) | ||
101 | { | ||
102 | char buf[12]; | ||
103 | sprintf( buf, "%hi", nValue ); | ||
104 | addProperty( sName, buf ); | ||
105 | } | ||
106 | |||
107 | void XmlDocument::addProperty( const char *sName, const int nValue ) | ||
108 | { | ||
109 | char buf[12]; | ||
110 | sprintf( buf, "%li", nValue ); | ||
111 | addProperty( sName, buf ); | ||
112 | } | ||
113 | |||
114 | void XmlDocument::addProperty( const char *sName, const unsigned long nValue ) | ||
115 | { | ||
116 | char buf[12]; | ||
117 | sprintf( buf, "%li", nValue ); | ||
118 | addProperty( sName, buf ); | ||
119 | } | ||
120 | |||
121 | void XmlDocument::addProperty( const char *sName, const long nValue ) | ||
122 | { | ||
123 | char buf[12]; | ||
124 | sprintf( buf, "%li", nValue ); | ||
125 | addProperty( sName, buf ); | ||
126 | } | ||
127 | |||
128 | void XmlDocument::addProperty( const char *sName, const double dValue ) | ||
129 | { | ||
130 | char buf[40]; | ||
131 | sprintf( buf, "%f", dValue ); | ||
132 | addProperty( sName, buf ); | ||
133 | } | ||
134 | |||
135 | void XmlDocument::setContent( const char *sContent ) | ||
136 | { | ||
137 | if( pCurrent ) | ||
138 | { | ||
139 | pCurrent->setContent( sContent ); | ||
140 | } | ||
141 | } | ||
142 | |||