diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-05-09 15:04:31 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-05-09 15:04:31 +0000 |
commit | ad92dc50b7cdf7cfe086f21d19442d03a90fd05d (patch) | |
tree | 9ca6f7bde704cb44276a05b6e83f36754e07f732 /src/old/xmlwriter.cpp | |
parent | 2e035fee36768e3c765b7f5dc10bf0a3b7d2448b (diff) | |
download | libbu++-ad92dc50b7cdf7cfe086f21d19442d03a90fd05d.tar.gz libbu++-ad92dc50b7cdf7cfe086f21d19442d03a90fd05d.tar.bz2 libbu++-ad92dc50b7cdf7cfe086f21d19442d03a90fd05d.tar.xz libbu++-ad92dc50b7cdf7cfe086f21d19442d03a90fd05d.zip |
Just a few things re-arranged, moved the new taf/xml systems to the inprogress
directory, and moved the old xml system in, so it will require heavy changes.
Diffstat (limited to 'src/old/xmlwriter.cpp')
-rw-r--r-- | src/old/xmlwriter.cpp | 173 |
1 files changed, 0 insertions, 173 deletions
diff --git a/src/old/xmlwriter.cpp b/src/old/xmlwriter.cpp deleted file mode 100644 index 56880b6..0000000 --- a/src/old/xmlwriter.cpp +++ /dev/null | |||
@@ -1,173 +0,0 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include "xmlwriter.h" | ||
4 | |||
5 | XmlWriter::XmlWriter( const char *sIndent, XmlNode *pRoot ) : | ||
6 | XmlDocument( pRoot ) | ||
7 | { | ||
8 | if( sIndent == NULL ) | ||
9 | { | ||
10 | this->sIndent = ""; | ||
11 | } | ||
12 | else | ||
13 | { | ||
14 | this->sIndent = sIndent; | ||
15 | } | ||
16 | } | ||
17 | |||
18 | XmlWriter::~XmlWriter() | ||
19 | { | ||
20 | } | ||
21 | |||
22 | void XmlWriter::write() | ||
23 | { | ||
24 | write( getRoot(), sIndent.c_str() ); | ||
25 | } | ||
26 | |||
27 | void XmlWriter::write( XmlNode *pRoot, const char *sIndent ) | ||
28 | { | ||
29 | writeNode( pRoot, 0, sIndent ); | ||
30 | } | ||
31 | |||
32 | void XmlWriter::closeNode() | ||
33 | { | ||
34 | XmlDocument::closeNode(); | ||
35 | |||
36 | if( isCompleted() ) | ||
37 | { | ||
38 | write( getRoot(), sIndent.c_str() ); | ||
39 | } | ||
40 | } | ||
41 | |||
42 | void XmlWriter::writeIndent( int nIndent, const char *sIndent ) | ||
43 | { | ||
44 | if( sIndent == NULL ) return; | ||
45 | for( int j = 0; j < nIndent; j++ ) | ||
46 | { | ||
47 | writeString( sIndent ); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | std::string XmlWriter::escape( std::string sIn ) | ||
52 | { | ||
53 | std::string sOut; | ||
54 | |||
55 | std::string::const_iterator i; | ||
56 | for( i = sIn.begin(); i != sIn.end(); i++ ) | ||
57 | { | ||
58 | if( ((*i >= ' ' && *i <= '9') || | ||
59 | (*i >= 'a' && *i <= 'z') || | ||
60 | (*i >= 'A' && *i <= 'Z') ) && | ||
61 | (*i != '\"' && *i != '\'' && *i != '&') | ||
62 | ) | ||
63 | { | ||
64 | sOut += *i; | ||
65 | } | ||
66 | else | ||
67 | { | ||
68 | sOut += "&#"; | ||
69 | char buf[4]; | ||
70 | sprintf( buf, "%u", (unsigned char)*i ); | ||
71 | sOut += buf; | ||
72 | sOut += ';'; | ||
73 | } | ||
74 | } | ||
75 | |||
76 | return sOut; | ||
77 | } | ||
78 | |||
79 | void XmlWriter::writeNodeProps( XmlNode *pNode, int nIndent, const char *sIndent ) | ||
80 | { | ||
81 | for( int j = 0; j < pNode->getNumProperties(); j++ ) | ||
82 | { | ||
83 | writeString(" "); | ||
84 | writeString( pNode->getPropertyName( j ) ); | ||
85 | writeString("=\""); | ||
86 | writeString( escape( pNode->getProperty( j ) ).c_str() ); | ||
87 | writeString("\""); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | void XmlWriter::writeNode( XmlNode *pNode, int nIndent, const char *sIndent ) | ||
92 | { | ||
93 | if( pNode->hasChildren() ) | ||
94 | { | ||
95 | writeIndent( nIndent, sIndent ); | ||
96 | writeString("<"); | ||
97 | writeString( pNode->getName() ); | ||
98 | writeNodeProps( pNode, nIndent, sIndent ); | ||
99 | if( sIndent ) | ||
100 | writeString(">\n"); | ||
101 | else | ||
102 | writeString(">"); | ||
103 | |||
104 | if( pNode->getContent( 0 ) ) | ||
105 | { | ||
106 | writeIndent( nIndent+1, sIndent ); | ||
107 | if( sIndent ) | ||
108 | { | ||
109 | writeString( pNode->getContent( 0 ) ); | ||
110 | writeString("\n"); | ||
111 | } | ||
112 | else | ||
113 | writeString( pNode->getContent( 0 ) ); | ||
114 | } | ||
115 | |||
116 | int nNumChildren = pNode->getNumChildren(); | ||
117 | for( int j = 0; j < nNumChildren; j++ ) | ||
118 | { | ||
119 | writeNode( pNode->getChild( j ), nIndent+1, sIndent ); | ||
120 | if( pNode->getContent( j+1 ) ) | ||
121 | { | ||
122 | writeIndent( nIndent+1, sIndent ); | ||
123 | if( sIndent ) | ||
124 | { | ||
125 | writeString( pNode->getContent( j+1 ) ); | ||
126 | writeString("\n"); | ||
127 | } | ||
128 | else | ||
129 | writeString( pNode->getContent( j+1 ) ); | ||
130 | } | ||
131 | } | ||
132 | |||
133 | writeIndent( nIndent, sIndent ); | ||
134 | if( sIndent ) | ||
135 | { | ||
136 | writeString("</"); | ||
137 | writeString( pNode->getName() ); | ||
138 | writeString(">\n"); | ||
139 | } | ||
140 | else | ||
141 | { | ||
142 | writeString("</"); | ||
143 | writeString( pNode->getName() ); | ||
144 | writeString(">"); | ||
145 | } | ||
146 | } | ||
147 | else if( pNode->getContent() ) | ||
148 | { | ||
149 | writeIndent( nIndent, sIndent ); | ||
150 | writeString("<"); | ||
151 | writeString( pNode->getName() ); | ||
152 | writeNodeProps( pNode, nIndent, sIndent ); | ||
153 | writeString(">"); | ||
154 | writeString( pNode->getContent() ); | ||
155 | writeString("</"); | ||
156 | writeString( pNode->getName() ); | ||
157 | writeString(">"); | ||
158 | if( sIndent ) | ||
159 | writeString("\n"); | ||
160 | } | ||
161 | else | ||
162 | { | ||
163 | writeIndent( nIndent, sIndent ); | ||
164 | writeString("<"); | ||
165 | writeString( pNode->getName() ); | ||
166 | writeNodeProps( pNode, nIndent, sIndent ); | ||
167 | if( sIndent ) | ||
168 | writeString("/>\n"); | ||
169 | else | ||
170 | writeString("/>"); | ||
171 | } | ||
172 | } | ||
173 | |||