423,491 Members | 1,422 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,491 IT Pros & Developers. It's quick & easy.

string to XmlNode

P: n/a
Given a string value representing an Xml-Element. What is the easyiest way
to get a XmlNode from it?
Sep 13 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a


Christof Nordiek wrote:
Given a string value representing an Xml-Element. What is the easyiest way
to get a XmlNode from it?
With .NET 1.x e.g.
XmlTextReader xmlReader = new XmlTextReader(new
StringReader(stringVariable));

// if you already have an XmlDocument then use that, otherwise
// create one
XmlDocument xmlDocument = new XmlDocument();
XmlNode node = xmlDocument.ReadNode(xmlReader);

The node can the be inserted/used as needed.

With .NET 2.0 you should use XmlReader.Create to create an XmlReader,
otherwise the code is the same. And XmlTextReader is still around in
..NET 2.0 so the code would even work without change, only using
XmlReader.Create is preferred in .NET 2.0.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 13 '06 #2

P: n/a
Check the documentation out on MSDN here

http://msdn2.microsoft.com/en-us/library/fb63z0tw.aspx

"Christof Nordiek" <cn@nospam.dewrote in message
news:e8**************@TK2MSFTNGP06.phx.gbl...
Given a string value representing an Xml-Element. What is the easyiest way
to get a XmlNode from it?

Sep 13 '06 #3

P: n/a
Thanks Martin

exactly what i needed.

"Martin Honnen" <ma*******@yahoo.deschrieb im Newsbeitrag
news:Ou*************@TK2MSFTNGP06.phx.gbl...
>

Christof Nordiek wrote:
>Given a string value representing an Xml-Element. What is the easyiest
way to get a XmlNode from it?

With .NET 1.x e.g.
XmlTextReader xmlReader = new XmlTextReader(new
StringReader(stringVariable));

// if you already have an XmlDocument then use that, otherwise
// create one
XmlDocument xmlDocument = new XmlDocument();
XmlNode node = xmlDocument.ReadNode(xmlReader);

The node can the be inserted/used as needed.

With .NET 2.0 you should use XmlReader.Create to create an XmlReader,
otherwise the code is the same. And XmlTextReader is still around in .NET
2.0 so the code would even work without change, only using
XmlReader.Create is preferred in .NET 2.0.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Sep 13 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.