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>