467,118 Members | 993 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,118 developers. It's quick & easy.

string to XmlNode

Given a string value representing an Xml-Element. What is the easyiest way
to get a XmlNode from it?
Sep 13 '06 #1
  • viewed: 51551
Share:
3 Replies


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
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
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.

Similar topics

2 posts views Thread by David Elliott | last post: by
3 posts views Thread by Mahesh Devjibhai Dhola | last post: by
5 posts views Thread by Paul | last post: by
7 posts views Thread by Jeppe BS | last post: by
7 posts views Thread by BluDog | last post: by
5 posts views Thread by Sharon | last post: by
14 posts views Thread by sani723 | last post: by
5 posts views Thread by =?Utf-8?B?VGhlIE1hbiBGcm9tIFNRTA==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.