diff options
Diffstat (limited to 'src/old/xmlwriter.cpp')
-rw-r--r-- | src/old/xmlwriter.cpp | 167 |
1 files changed, 0 insertions, 167 deletions
diff --git a/src/old/xmlwriter.cpp b/src/old/xmlwriter.cpp deleted file mode 100644 index 7dc6ca9..0000000 --- a/src/old/xmlwriter.cpp +++ /dev/null | |||
@@ -1,167 +0,0 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include "xmlwriter.h" | ||
4 | |||
5 | XmlWriter::XmlWriter( const Bu::FString &sIndent, XmlNode *pRoot ) : | ||
6 | XmlDocument( pRoot ), | ||
7 | sIndent( sIndent ) | ||
8 | { | ||
9 | } | ||
10 | |||
11 | XmlWriter::~XmlWriter() | ||
12 | { | ||
13 | } | ||
14 | |||
15 | void XmlWriter::write() | ||
16 | { | ||
17 | write( getRoot(), sIndent.c_str() ); | ||
18 | } | ||
19 | |||
20 | void XmlWriter::write( XmlNode *pRoot, const Bu::FString &sIndent ) | ||
21 | { | ||
22 | writeNode( pRoot, 0, sIndent ); | ||
23 | } | ||
24 | |||
25 | void XmlWriter::closeNode() | ||
26 | { | ||
27 | XmlDocument::closeNode(); | ||
28 | |||
29 | if( isCompleted() ) | ||
30 | { | ||
31 | write( getRoot(), sIndent.c_str() ); | ||
32 | } | ||
33 | } | ||
34 | |||
35 | void XmlWriter::writeIndent( int nIndent, const Bu::FString &sIndent ) | ||
36 | { | ||
37 | if( sIndent == NULL ) return; | ||
38 | for( int j = 0; j < nIndent; j++ ) | ||
39 | { | ||
40 | writeString( sIndent ); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | Bu::FString XmlWriter::escape( const Bu::FString &sIn ) | ||
45 | { | ||
46 | Bu::FString sOut; | ||
47 | |||
48 | int nMax = sIn.getSize(); | ||
49 | for( int j = 0; j < nMax; j++ ) | ||
50 | { | ||
51 | char c = sIn[j]; | ||
52 | if( ((c >= ' ' && c <= '9') || | ||
53 | (c >= 'a' && c <= 'z') || | ||
54 | (c >= 'A' && c <= 'Z') ) && | ||
55 | (c != '\"' && c != '\'' && c != '&') | ||
56 | ) | ||
57 | { | ||
58 | sOut += c; | ||
59 | } | ||
60 | else | ||
61 | { | ||
62 | sOut += "&#"; | ||
63 | char buf[4]; | ||
64 | sprintf( buf, "%u", (unsigned char)c ); | ||
65 | sOut += buf; | ||
66 | sOut += ';'; | ||
67 | } | ||
68 | } | ||
69 | |||
70 | return sOut; | ||
71 | } | ||
72 | |||
73 | void XmlWriter::writeNodeProps( XmlNode *pNode, int nIndent, const Bu::FString &sIndent ) | ||
74 | { | ||
75 | for( int j = 0; j < pNode->getNumProperties(); j++ ) | ||
76 | { | ||
77 | writeString(" "); | ||
78 | //writeString( pNode->getPropertyName( j ) ); | ||
79 | writeString("=\""); | ||
80 | //writeString( escape( pNode->getProperty( j ) ).c_str() ); | ||
81 | writeString("\""); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | void XmlWriter::writeNode( XmlNode *pNode, int nIndent, const Bu::FString &sIndent ) | ||
86 | { | ||
87 | if( pNode->hasChildren() ) | ||
88 | { | ||
89 | writeIndent( nIndent, sIndent ); | ||
90 | writeString("<"); | ||
91 | writeString( pNode->getName() ); | ||
92 | writeNodeProps( pNode, nIndent, sIndent ); | ||
93 | if( sIndent != "" ) | ||
94 | writeString(">\n"); | ||
95 | else | ||
96 | writeString(">"); | ||
97 | /* | ||
98 | if( pNode->getContent( 0 ) ) | ||
99 | { | ||
100 | writeIndent( nIndent+1, sIndent ); | ||
101 | if( sIndent != "" ) | ||
102 | { | ||
103 | writeString( pNode->getContent( 0 ) ); | ||
104 | writeString("\n"); | ||
105 | } | ||
106 | else | ||
107 | writeString( pNode->getContent( 0 ) ); | ||
108 | } | ||
109 | |||
110 | int nNumChildren = pNode->getNumChildren(); | ||
111 | for( int j = 0; j < nNumChildren; j++ ) | ||
112 | { | ||
113 | writeNode( pNode->getChild( j ), nIndent+1, sIndent ); | ||
114 | if( pNode->getContent( j+1 ) ) | ||
115 | { | ||
116 | writeIndent( nIndent+1, sIndent ); | ||
117 | if( sIndent ) | ||
118 | { | ||
119 | writeString( pNode->getContent( j+1 ) ); | ||
120 | writeString("\n"); | ||
121 | } | ||
122 | else | ||
123 | writeString( pNode->getContent( j+1 ) ); | ||
124 | } | ||
125 | } | ||
126 | */ | ||
127 | writeIndent( nIndent, sIndent ); | ||
128 | if( sIndent != "" ) | ||
129 | { | ||
130 | writeString("</"); | ||
131 | writeString( pNode->getName() ); | ||
132 | writeString(">\n"); | ||
133 | } | ||
134 | else | ||
135 | { | ||
136 | writeString("</"); | ||
137 | writeString( pNode->getName() ); | ||
138 | writeString(">"); | ||
139 | } | ||
140 | }/* | ||
141 | else if( pNode->getContent() ) | ||
142 | { | ||
143 | writeIndent( nIndent, sIndent ); | ||
144 | writeString("<"); | ||
145 | writeString( pNode->getName() ); | ||
146 | writeNodeProps( pNode, nIndent, sIndent ); | ||
147 | writeString(">"); | ||
148 | writeString( pNode->getContent() ); | ||
149 | writeString("</"); | ||
150 | writeString( pNode->getName() ); | ||
151 | writeString(">"); | ||
152 | if( sIndent ) | ||
153 | writeString("\n"); | ||
154 | }*/ | ||
155 | else | ||
156 | { | ||
157 | writeIndent( nIndent, sIndent ); | ||
158 | writeString("<"); | ||
159 | writeString( pNode->getName() ); | ||
160 | writeNodeProps( pNode, nIndent, sIndent ); | ||
161 | if( sIndent != "" ) | ||
162 | writeString("/>\n"); | ||
163 | else | ||
164 | writeString("/>"); | ||
165 | } | ||
166 | } | ||
167 | |||