本文介绍了我如何解析我的这个xml字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< channeldata>
< subscreiptionid> subid</subscriptionid>
< domian> todomian</domin>
< channel> tochannel</channel>

</channeldata>

<channeldata>
<subscreiptionid>subid</subscriptionid>
<domian>todomian</domin>
<channel>tochannel</channel>

</channeldata>

推荐答案


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


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字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 06:33