aboutsummaryrefslogtreecommitdiff
path: root/src/xmlwriter.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-06-12 01:28:27 +0000
committerMike Buland <eichlan@xagasoft.com>2007-06-12 01:28:27 +0000
commit4cb166570a8e2e97216bf6c7aeb99b971ff58ad7 (patch)
treeb8d22af96957666ac761b6ca1b57da1eee2e56a5 /src/xmlwriter.cpp
parentb6f50f249ba3b18c597531a2d5dbc45f7bfa3eaa (diff)
downloadlibbu++-4cb166570a8e2e97216bf6c7aeb99b971ff58ad7.tar.gz
libbu++-4cb166570a8e2e97216bf6c7aeb99b971ff58ad7.tar.bz2
libbu++-4cb166570a8e2e97216bf6c7aeb99b971ff58ad7.tar.xz
libbu++-4cb166570a8e2e97216bf6c7aeb99b971ff58ad7.zip
Moved out the xml system again. I think that if I am going to do it again,
I'm going to do it over from scratch, that was just painful. Also, started in again on the server system, it's looking pretty good, already got connections working, next up is managing data flow through clients and protocols!
Diffstat (limited to 'src/xmlwriter.cpp')
-rw-r--r--src/xmlwriter.cpp167
1 files changed, 0 insertions, 167 deletions
diff --git a/src/xmlwriter.cpp b/src/xmlwriter.cpp
deleted file mode 100644
index 7dc6ca9..0000000
--- a/src/xmlwriter.cpp
+++ /dev/null
@@ -1,167 +0,0 @@
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