从字符串解析XML
我有一个xml字符串:
Result : this is the result
我如何使用XMLReader类解析XML以将“this is the result”作为字符串返回。
thanx!
var r = System.Xml.XmlReader.Create(new System.IO.StringReader(" Result : this is the result ")) 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())