Xia
Xia

Reputation: 45

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 check the contents.

Upvotes: 2

Views: 924

Answers (3)

John Saunders
John Saunders

Reputation: 161801

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.

Upvotes: 0

carlosfigueira
carlosfigueira

Reputation: 87298

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);

Upvotes: 0

Fredrik Mörk
Fredrik Mörk

Reputation: 158349

Have it write to a MemoryStream or StringBuilder instead of a file. That will allow you to check the output.

Upvotes: 3

Related Questions