加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 05:25:22 所属栏目:百科 来源:网络整理
导读:如XML文件: ?xml version="1.0" encoding="utf-8" ?SendExResp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"PayCount1/PayCountBlackWords /ErrorMobiles /BlackMobiles /BatchSendID00000000-0000

如XML文件:


<?xml version="1.0" encoding="utf-8" ?>
<SendExResp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<PayCount>1</PayCount>
	<BlackWords />
	<ErrorMobiles />
	<BlackMobiles />
	<BatchSendID>00000000-0000-0000-0000-000000000000</BatchSendID>
	<Result>aaa</Result>
	<ErrorDesc>成功</ErrorDesc>
</SendExResp>

C#代码

 String path = System.AppDomain.CurrentDomain.BaseDirectory + "//return.xml";

                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(path);

                XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmldoc.NameTable); //namespace 
                namespaceManager.AddNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
                namespaceManager.AddNamespace("xsd","http://www.w3.org/2001/XMLSchema");

                XmlNode node = xmldoc.SelectSingleNode("//SendExResp/Result",namespaceManager);

                this.Label1.Text = node.InnerText;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读