tags:

views:

71

answers:

2

Hey all.

I have a xml string:

<Test> Result : this is the result</Test>

How do i parse XML using XMLReader class to get "this is the result" as a string back.

thanx !

+1  A: 

Just create an xml reader using that string and use it for parsing

var reader = System.Xml.XmlReader.Create(new System.IO.StringReader(<xmlstring>))
Dror Helper
when i do the "using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))" the reader says there are no attributes. Can some1 give me an example please?
no9
@Dror Helper: You need to expand your answer to actually answer the "How do i parse XML using XMLReader class to get "this is the result" as a string back." bit. You've only really shown a hint of the way to go, not a solution.
Rob Levine
+3  A: 
var r = System.Xml.XmlReader.Create(new System.IO.StringReader("<Test> Result : this is the result</Test>"))
while (r.Read()) {
   if (r.NodeType == XmlNodeType.Element && r.LocalName == "Test") {
     Console.Write(r.ReadElementContentAsString());
   }
}
dnolan
works, just replace <xmlstring> by "<Test> Result : this is the result</Test>"
Simpzon