Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

generating an XmlDocument from an XmlWriter

2,676 views
Skip to first unread message

Andy Fish

unread,
Nov 24, 2008, 11:49:17 AM11/24/08
to
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.

Andy


Martin Honnen

unread,
Nov 24, 2008, 12:04:10 PM11/24/08
to

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/

DH

unread,
Nov 24, 2008, 12:08:39 PM11/24/08
to

Andy Fish

unread,
Nov 24, 2008, 2:04:43 PM11/24/08
to

"Martin Honnen" <maho...@yahoo.de> wrote in message
news:uvUUualT...@TK2MSFTNGP03.phx.gbl...

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


0 new messages