我如何解析我的这个xml字符串 [英] how can i parse my this xml string
本文介绍了我如何解析我的这个xml字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< channeldata>
< subscreiptionid> subid</subscriptionid>
< domian> todomian</domin>
< channel> tochannel</channel>
</channeldata>
<channeldata>
<subscreiptionid>subid</subscriptionid>
<domian>todomian</domin>
<channel>tochannel</channel>
</channeldata>
推荐答案
Google是您的朋友:很好,经常拜访他.与在这里发布问题相比,他可以更快地回答问题.
快速搜索给出了以下内容:如何使用Visual C#从文件中读取XML [
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...
A very quick search gave this: How to read XML from a file by using Visual C#[^]
XmlTextReader r = new XmlTextReader("xml file path");
string strval1,strval2,strval3;
r.Read();
while (r.Read())
{
if (r.NodeType == XmlNodeType.Element)
{
if (r.Name =="subscreiptionid" )
{
r.Read();
strval1 = Convert.ToString(r.Value);
}
elseif(r.Name =="domain" )
{
r.Read();
strval2 = Convert.ToString(r.Value);
}
elseif(r.Name =="channel" )
{
r.Read();
strval3 = Convert.ToString(r.Value);
}
}
}
这里是:
Here it is :
XmlDocument chanelData= new XmlDocument();
chanelData.LoadXml(@"<channeldata>
<subscriptionid>subid</subscriptionid>
<domain>todomian</domain>
<channel>tochannel</channel>
</channeldata>");
foreach (XmlNode node in chanelData.SelectNodes("/channeldata/*"))
Console.WriteLine(node.Name + " = " +node.InnerText);
Console.ReadKey();
祝你好运
Good Luck
这篇关于我如何解析我的这个xml字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文