aboutsummaryrefslogtreecommitdiff
path: root/src/old/xmlwriter.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-07-03 00:28:59 +0000
committerMike Buland <eichlan@xagasoft.com>2007-07-03 00:28:59 +0000
commitac517a2b7625e0aa0862679e961c6349f859ea3b (patch)
treee3e27a6b9bd5e2be6150088495c91fc91786ad9d /src/old/xmlwriter.cpp
parentf8d4301e9fa4f3709258505941e37fab2eadadc6 (diff)
parentbd865cee5f89116c1f054cd0e5c275e97c2d0a9b (diff)
downloadlibbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.gz
libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.bz2
libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.xz
libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.zip
The reorg is being put in trunk, I think it's ready. Now we just get to find
out how many applications won't work anymore :)
Diffstat (limited to 'src/old/xmlwriter.cpp')
-rw-r--r--src/old/xmlwriter.cpp167
1 files changed, 167 insertions, 0 deletions
diff --git a/src/old/xmlwriter.cpp b/src/old/xmlwriter.cpp
new file mode 100644
index 0000000..7dc6ca9
--- /dev/null
+++ b/src/old/xmlwriter.cpp
@@ -0,0 +1,167 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include "xmlwriter.h"
4
5XmlWriter::XmlWriter( const Bu::FString &sIndent, XmlNode *pRoot ) :
6 XmlDocument( pRoot ),
7 sIndent( sIndent )
8{
9}
10
11XmlWriter::~XmlWriter()
12{
13}
14
15void XmlWriter::write()
16{
17 write( getRoot(), sIndent.c_str() );
18}
19
20void XmlWriter::write( XmlNode *pRoot, const Bu::FString &sIndent )
21{
22 writeNode( pRoot, 0, sIndent );
23}
24
25void XmlWriter::closeNode()
26{
27 XmlDocument::closeNode();
28
29 if( isCompleted() )
30 {
31 write( getRoot(), sIndent.c_str() );
32 }
33}
34
35void 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
44Bu::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
73void 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
85void 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