Andy Fish wrote:
> hi,
>
> 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.
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/