summaryrefslogtreecommitdiff
path: root/src/xmldocument.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/xmldocument.cpp')
-rw-r--r--src/xmldocument.cpp146
1 files changed, 143 insertions, 3 deletions
diff --git a/src/xmldocument.cpp b/src/xmldocument.cpp
index cb21826..d7867d5 100644
--- a/src/xmldocument.cpp
+++ b/src/xmldocument.cpp
@@ -1,9 +1,149 @@
1#include "xmldocument.h" 1#include <stdio.h>
2#include <stdlib.h>
3#include "xmlwriter.h"
2 4
3Bu::XmlDocument::XmlDocument() 5XmlDocument::XmlDocument( XmlNode *pRoot )
4{ 6{
7 this->pRoot = pRoot;
8 pCurrent = NULL;
9 bCompleted = (pRoot!=NULL);
5} 10}
6 11
7Bu::XmlDocument::~XmlDocument() 12XmlDocument::~XmlDocument()
8{ 13{
14 if( pRoot )
15 {
16 delete pRoot;
17 }
9} 18}
19
20void 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
38void XmlDocument::setName( const char *sName )
39{
40 pCurrent->setName( sName );
41}
42
43bool XmlDocument::isCompleted()
44{
45 return bCompleted;
46}
47
48XmlNode *XmlDocument::getRoot()
49{
50 return pRoot;
51}
52
53XmlNode *XmlDocument::detatchRoot()
54{
55 XmlNode *pTemp = pRoot;
56 pRoot = NULL;
57 return pTemp;
58}
59
60XmlNode *XmlDocument::getCurrent()
61{
62 return pCurrent;
63}
64
65void XmlDocument::closeNode()
66{
67 if( pCurrent != NULL )
68 {
69 pCurrent = pCurrent->getParent();
70
71 if( pCurrent == NULL )
72 {
73 bCompleted = true;
74 }
75 }
76}
77
78void XmlDocument::addProperty( const char *sName, const char *sValue )
79{
80 if( pCurrent )
81 {
82 pCurrent->addProperty( sName, sValue );
83 }
84}
85
86void XmlDocument::addProperty( const char *sName, const unsigned char nValue )
87{
88 char buf[12];
89 sprintf( buf, "%hhi", nValue );
90 addProperty( sName, buf );
91}
92
93void XmlDocument::addProperty( const char *sName, const char nValue )
94{
95 char buf[12];
96 sprintf( buf, "%hhi", nValue );
97 addProperty( sName, buf );
98}
99
100void XmlDocument::addProperty( const char *sName, const unsigned short nValue )
101{
102 char buf[12];
103 sprintf( buf, "%hi", nValue );
104 addProperty( sName, buf );
105}
106
107void XmlDocument::addProperty( const char *sName, const short nValue )
108{
109 char buf[12];
110 sprintf( buf, "%hi", nValue );
111 addProperty( sName, buf );
112}
113
114void XmlDocument::addProperty( const char *sName, const int nValue )
115{
116 char buf[12];
117 sprintf( buf, "%d", nValue );
118 addProperty( sName, buf );
119}
120
121void XmlDocument::addProperty( const char *sName, const unsigned long nValue )
122{
123 char buf[12];
124 sprintf( buf, "%li", nValue );
125 addProperty( sName, buf );
126}
127
128void XmlDocument::addProperty( const char *sName, const long nValue )
129{
130 char buf[12];
131 sprintf( buf, "%li", nValue );
132 addProperty( sName, buf );
133}
134
135void XmlDocument::addProperty( const char *sName, const double dValue )
136{
137 char buf[40];
138 sprintf( buf, "%f", dValue );
139 addProperty( sName, buf );
140}
141
142void XmlDocument::setContent( const char *sContent )
143{
144 if( pCurrent )
145 {
146 pCurrent->setContent( sContent );
147 }
148}
149