all groups > dotnet windows forms > april 2006 >
You're in the

dotnet windows forms

group:

XML String


XML String Martin
4/28/2006 12:00:00 AM
dotnet windows forms:
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?

Re: XML String Greg Young [MVP]
4/28/2006 3:13:38 AM
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
[quoted text, click to view]

Re: XML String Claes Bergefall
4/28/2006 10:23:04 AM
XmlDocument doc = new XmlDocument();
doc.LoadXml(myString);

/claes

[quoted text, click to view]

AddThis Social Bookmark Button