Investigating XMLWriter object
How can I see the XML contents of fully populated XmlWriter
object while debugging. My silverlight application doesn't permit to actually write to a file and che开发者_如何学Gock the contents.
Have it write to a MemoryStream
or StringBuilder
instead of a file. That will allow you to check the output.
You can create the XmlWriter based on a MemoryStream, then unencode the bytes from the memory stream and display it in a text box, for example.
MemoryStream ms = new MemoryStream();
XmlWriterSettings ws = new XmlWriterSettings();
ws.Encoding = Encoding.UTF8;
XmlWriter w = XmlWriter.Create(ms, ws);
// populate the writer
w.Flush();
textBox1.Text = Encoding.UTF8.GetString(ms.GetBuffer(), 0, (int)ms.Position);
An XmlReader
is not "populated". It represents the state of an XML parsing operation, as that operation is in progress. This state will change as the XML is read.
精彩评论