I would like to make an XmlWriter write directly into an XmlDocument rather
than writing it to a stream and then having to load it into a document.
in the documentation for XmlWriter it rather tantalizingly says:
"... For example, if you are using the XmlWriter to populate an XmlDocument
..."
(just google for that phrase to see it in context) which implies that it it
possible to do what I want, but I can't see any way of doing that.
Andy
XmlDocument doc = new XmlDocument();
using (XmlWriter writer = doc.CreateNavigator().AppendChild())
{
writer.WriteStartDocument();
writer.WriteStartElement("root");
writer.WriteElementString("foo", "bar");
writer.WriteEndElement();
writer.WriteEndDocument();
}
.NET 2.0 or later.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Thanks martin - I had a funny feeling i'd looked for this before and as soon
as I saw that "CreateNavigator().AppendChild())" call I remembered it - and
i also remember thinking how difficult it was to find last time