XmlDocument xd = new XmlDocument();
xd.Load("soap.xml");
XmlNamespaceManager man = new XmlNamespaceManager(xd.NameTable);
man.AddNamespace("soap", "http://www.w3.org/2001/12/soap-envelope");
man.AddNamespace("m", "http://www.w3school.com.cn/prices");
string aa = xd.SelectSingleNode("/soap:Envelope/soap:Body/m:GetPrice/m:Item",man).InnerText;
代码中用到的soap.xml文件内容如下:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body>
<m:GetPrice xmlns:m="http://www.w3school.com.cn/prices">
<m:Item>Apples</m:Item>
</m:GetPrice>
</soap:Body>
</soap:Envelope>
本文详细介绍了如何使用C#解析XML文档,并通过XMLNamespaceManager处理不同命名空间的方法。以SOAP XML为例,演示了如何获取特定节点的文本内容。

被折叠的 条评论
为什么被折叠?



