Derek,
Thanks for your suggestion, I used it to work out the below is the VB. With
regard to my code I would like to further optimize it by removing the xrsp
object (XmlDocument), from my limited understanding of streams it appears
that I do not need this object but should be able to pipe the StreamReader
directly in the the XmlTextWriter but cannot determine the appropriate
methods, and suggestions?
Thanks Again,
Dan
Dim wproc As New WebDav
Dim rsp As System.Net.HttpWebResponse
Try
Me.txtXMLResponse.Text = "Sending Request ...."
rsp = wproc.ProcessRequest(Me.txtURI.Text, _
CStr(Me.cmbMethod.SelectedItem), txtXMLRequest.Text)
Dim xrsp As New Xml.XmlDocument
Dim sr As New System.IO.StreamReader(rsp.GetResponseStream)
xrsp.LoadXml(sr.ReadToEnd)
sr.Close()
sr = Nothing
Dim buf As New System.Text.StringBuilder
Dim read As New System.IO.StringWriter(buf)
Dim xw As New System.Xml.XmlTextWriter(read)
xw.Formatting = Xml.Formatting.Indented
xw.Indentation = 3
xrsp.WriteTo(xw)
xw.Close()
xw = Nothing
Me.txtXMLResponse.Text = buf.ToString
Catch ex As Exception
Me.txtXMLResponse.Text = ex.ToString
Finally
wproc = Nothing
If Not IsNothing(rsp) Then
rsp.Close()
rsp = Nothing
End If
End Try
"Derek Harmon" <lo*******@msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"solex" <so***@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Is there an easy way to add whitespace to an XML document?
Yes, write out the XML document into a String through an
XmlTextWriter with it's indenting turned on.
- - - XmlFormattedTextBox.cs (excerpt)
using System;
using System.IO;
using System.Text;
using System.Xml;
// . . .
// Create a string buffer and wrap it in a StringWriter (TextWriter)
// and XmlTextWriter (which needs a TextWriter to wrap).
//
StringBuilder stringBuf = new StringBuilder( );
StringWriter strWriter = new StringWriter( stringBuf);
XmlTextWriter xmlWriter = new XmlTextWriter( strWriter);
// Set formatting on the XmlTextWriter to indent.
//
xmlWriter.Formatting = Formatting.Indented;
// Write the XmlDocument containing the WebDAV request
// to the XmlTextWriter (it trickles down into the string buffer).
//
xmlDoc.WriteTo( xmlWriter);
// Set the TextBox's Text property to the String based on the
// string buffer that received the formatted XML serialization.
//
TextBox1.Text = stringBuf.ToString( );
// . . .
- - -
Derek Harmon