/[dgee]/dgee/cslib/DotGNU/XmlRpc/XmlRpcWriter.cs
ViewVC logotype

Diff of /dgee/cslib/DotGNU/XmlRpc/XmlRpcWriter.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.2.3 by npg, Tue Jul 22 10:58:11 2003 UTC revision 1.1.2.4 by npg, Tue Jul 22 14:42:25 2003 UTC
# Line 25  using System; Line 25  using System;
25  using System.Collections;  using System.Collections;
26  using System.IO;  using System.IO;
27  using System.CodeDom.Compiler;  using System.CodeDom.Compiler;
28    using System.Xml;
29    
30  namespace DotGNU.XmlRpc  namespace DotGNU.XmlRpc
31  {  {  
     
32    // For now, indentation is the default since it makes it easier for    // For now, indentation is the default since it makes it easier for
33    // a human to read the output.  later the output should not be    // a human to read the output.  later the output should not be
34    // formatted at all.  ideally it should be an unindented block    // formatted at all.  ideally it should be an unindented block.
35      // Ideally XmlTextWriter should write the tags, but it's indentation
36      // is too broken so that its more human readable and debuggable.
37      // Grrr Grrr Grrrrr
38    public class XmlRpcWriter    public class XmlRpcWriter
39    {    {
40      private IndentedTextWriter writer;      private IndentedTextWriter writer;
# Line 75  namespace DotGNU.XmlRpc Line 77  namespace DotGNU.XmlRpc
77        string tag;        string tag;
78        if( o is int ) {        if( o is int ) {
79          tag = "i4";          tag = "i4";
80          WriteObject( tag, o );          Write( tag, o );
81        }        }
82        else if( o is double ) {        else if( o is double ) {
83          tag = "double";          tag = "double";
84          WriteObject( tag, o );          Write( tag, o );
85        }        }
86        else if( o is string ) {        else if( o is string ) {
87          tag = "string";          tag = "string";
88          WriteObject( tag, o );          Write( tag, o );
89        }        }
90        else if( o is bool ) {        else if( o is bool ) {
91          tag = "boolean";          tag = "boolean";
92          WriteObject( tag, o );          Write( tag, o );
93        }        }
94        else if( o is DateTime ) {        else if( o is DateTime ) {
95          tag = "dateTime.iso8601";          tag = "dateTime.iso8601";
96          WriteObject( tag, o );          Write( tag, o );
97        }        }
98        else if( o is byte[] ) {        else if( o is byte[] ) {
99          tag = "base64";          StringWriter sw = new StringWriter();
100          WriteObject( tag, o );          XmlTextWriter tw = new XmlTextWriter( sw );
101            byte[] buf = (byte[])o;
102            tw.WriteStartElement( "base64" );
103            tw.WriteBase64( buf, 0, buf.Length);
104            tw.WriteEndElement();
105            //tag = "base64";
106            //Write( tag, o );
107            writer.WriteLine( sw );
108        }        }
109        else if( o is XmlRpcStruct ) {        else if( o is XmlRpcStruct ) {
110          tag = "struct";          tag = "struct";
# Line 112  namespace DotGNU.XmlRpc Line 121  namespace DotGNU.XmlRpc
121            writer.WriteLine( "</name>" );            writer.WriteLine( "</name>" );
122            writer.WriteLine( "<value>" );            writer.WriteLine( "<value>" );
123            writer.Indent++;            writer.Indent++;
124            this.Write( entry.Value );            Write( entry.Value );
125            writer.Indent--;            writer.Indent--;
126            writer.WriteLine( "</value>" );            writer.WriteLine( "</value>" );
127            writer.Indent--;            writer.Indent--;
# Line 123  namespace DotGNU.XmlRpc Line 132  namespace DotGNU.XmlRpc
132        }        }
133        else if( o is XmlRpcArray ) {        else if( o is XmlRpcArray ) {
134          tag = "array";          tag = "array";
         Console.Out.WriteLine( "An array" );  
           
135          writer.WriteLine( "<array>" );          writer.WriteLine( "<array>" );
136          writer.Indent++;          writer.Indent++;
137          writer.WriteLine( "<data>" );          writer.WriteLine( "<data>" );
# Line 143  namespace DotGNU.XmlRpc Line 150  namespace DotGNU.XmlRpc
150        }        }
151      }      }
152            
153      private void WriteObject( string tag, object o )      private void Write( string tag, object o )
154      {      {
155        writer.WriteLine( "<{0}>", tag );        writer.WriteLine( "<{0}>", tag );
156        writer.Indent++;        writer.Indent++;
# Line 158  namespace DotGNU.XmlRpc Line 165  namespace DotGNU.XmlRpc
165        Write( s );        Write( s );
166        WriteTail();        WriteTail();
167    
168          /*
169          
170          pile of bollocks.  i thought XmlTextWriter was re-implemented?
171          The indentation is still horribly broken
172          
173          StringWriter sw = new StringWriter();
174          XmlTextWriter tw = new XmlTextWriter( sw );
175          tw.Formatting = Formatting.Indented;
176          tw.Indentation = 4;
177    
178          tw.WriteStartDocument();
179          tw.WriteStartElement( "foo" );
180          tw.WriteStartElement( "bar" );
181          tw.WriteString( "hello there" );
182          tw.WriteEndElement();
183          tw.WriteEndElement();
184          tw.WriteEndDocument();
185          */
186    
187          //tw.Indentation=4;
188        return sw.ToString();        return sw.ToString();
189      }      }
190            

Legend:
Removed from v.1.1.2.3  
changed lines
  Added in v.1.1.2.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26