.net关于xml文件命名空间的解析读取

前端之家收集整理的这篇文章主要介绍了.net关于xml文件命名空间的解析读取前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

如XML文件:


  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <SendExResp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  3. <PayCount>1</PayCount>
  4. <BlackWords />
  5. <ErrorMobiles />
  6. <BlackMobiles />
  7. <BatchSendID>00000000-0000-0000-0000-000000000000</BatchSendID>
  8. <Result>aaa</Result>
  9. <ErrorDesc>成功</ErrorDesc>
  10. </SendExResp>@H_404_7@
  11. C#代码

  12.  String path = System.AppDomain.CurrentDomain.BaseDirectory + "//return.xml";
  13.                 XmlDocument xmldoc = new XmlDocument();
  14.                 xmldoc.Load(path);
  15.                 XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmldoc.NaMetable); //namespace 
  16.                 namespaceManager.AddNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
  17.                 namespaceManager.AddNamespace("xsd","http://www.w3.org/2001/XMLSchema");
  18.                 XmlNode node = xmldoc.SelectSingleNode("//SendExResp/Result",namespaceManager);
  19.                 this.Label1.Text = node.InnerText;
  20. @H_404_7@

猜你在找的XML相关文章