System.IO.StringReader
(1)
System.Xml.XmlDocument
(1)
XDocument.Parse
(1)
StreamReader
(1)
StringReader
(1)
TextReader
(1)
XDocument
(1)
XElement
(1)

Parsing XML in string variable?

Asked By VMI
09-Feb-10 09:18 AM
I have a method that returns a string that contains XML, and I need to parse
that string (ie. find specific keys).

How can I do this? I found one that searches a Stream, but I do not know how
to convert from string to stream.

Thanks.

hi vmi,you could use the System.Xml.

Matthias Truxa replied to VMI
09-Feb-10 09:52 AM
hi vmi,

you could use the System.Xml.XmlDocument class, simply make a new instance
and use the LoadXml-Method (does not properly load string with encoding
markers).
You could also use the .NET 3.5 System.Xml.Linq.XElement.
There are several utility classes to read from strings and streams and vice
versa, e.g. System.IO.StringReader & StreamReader, which are derived from
TextReader.
You need to experiment a little and look at their constructors to find what
you need, or you have to post exactly what you want and (hopefully) find
someone to complete the code.

Regards,
Matt

VMI wrote:XDocument doc = XDocument.

Martin Honnen replied to VMI
09-Feb-10 11:49 AM
XDocument doc = XDocument.Parse(yourMethod());

Then use LINQ to XML to find/access nodes:
http://msdn.microsoft.com/en-us/library/bb387098.aspx

--

Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/
Post Question To EggHeadCafe