簡體   English   中英

從字符串解析XML

[英]parse XML from string

我有一個xml字符串:

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

我如何使用XMLReader類解析XML以將“this is the result”作為字符串返回。

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>))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM