XML String

M

Martin

how do I create a XmlDocument object or a XmlDocumentFragment object or a
XmlNode objekt from a string?

I get a string like that:
<Node>
<ChildNode>Value</ChildNode>
</Node>

in a variable of type string. now I want to parse this string with xml
objects in order to get less work. is it possible?
 
G

Greg Young [MVP]

You will note that XMLDocument.Load has an overload for a TextReader.
http://msdn2.microsoft.com/en-us/library/ce3x426k(VS.80).aspx

StringReader
http://msdn2.microsoft.com/en-us/library/system.io.stringreader(VS.80).aspx
is a TextReader

You can create a StringReader for your string ...

string foo = "<somexml></somexml>";
TextReader Reader = new StringReader(foo);
XmlDocument.Load(Reader);

or shortenned to ..
string foo = "<somexml></somexml>";
XmlDocument.Load(new StringReader(foo));

Cheers,

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top