简体   繁体   中英

parse XML from string

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 !

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());
   }
}

只需使用该字符串创建一个xml阅读器并将其用于解析

var reader = System.Xml.XmlReader.Create(new System.IO.StringReader(<xmlstring>))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM