XML文件如下:
<?xml version="1.0" encoding="utf-8" ?>
- <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <soap:Body>
- <VerificationUserLoginResponse xmlns="http://tempuri.org/">
<VerificationUserLoginResult>false</VerificationUserLoginResult>
</VerificationUserLoginResponse>
</soap:Body>
</soap:Envelope>c#代码读取如下:
XmlDocument xmldoc = new XmlDocument();
XmlNode node1 = xmldoc.SelectSingleNode("/Envelope/Body/VerificationUserLoginResponse/VerificationUserLoginResult");
为什么读取不到值呢?node1始终为null,谁帮忙修改一下,谢谢啊。
<?xml version="1.0" encoding="utf-8" ?>
- <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <soap:Body>
- <VerificationUserLoginResponse xmlns="http://tempuri.org/">
<VerificationUserLoginResult>false</VerificationUserLoginResult>
</VerificationUserLoginResponse>
</soap:Body>
</soap:Envelope>c#代码读取如下:
XmlDocument xmldoc = new XmlDocument();
XmlNode node1 = xmldoc.SelectSingleNode("/Envelope/Body/VerificationUserLoginResponse/VerificationUserLoginResult");
为什么读取不到值呢?node1始终为null,谁帮忙修改一下,谢谢啊。
解决方案 »
- C#在控制台如何输出指定半径的圆?
- 如何执行多条sql语句,我看了好几个帖子都不行!!!
- 如何获的随机数?
- 怎么取网页的链接文字?
- js脚本动态生成text控件如何控制属性
- 用c#程序把文件做成压缩包该怎么做?
- 都问了很多的问题:c#2005中如何让用户在程序中设置“设置文件”也就是.settings的文件
- .netC/S程序访问ORACLE,不安装ORACLE客户端的前提下,使用ORACLE.DATA.ACCESS.DLL如何访问
- infopath help
- *^_^*怎么获得远程网络上文件的大小(还有进来看吧!)*^_^*
- 自定义泛型的定义及使用c#
- Winform 打包成EXE,安装后,Windows7可以运行,XP不行
doc .Load(Server.MapPath("~/1.xml"));
XmlNamespaceManager m = new XmlNamespaceManager(doc .NameTable);
m.AddNamespace("a", "");
m.AddNamespace("xs", "x");
m.AddNamespace("msdata", "urn:schemas-microsoft-com:xml-msdata");
XmlNodeList ns = d.SelectNodes("",m);
foreach (XmlNode n in ns)
{
}
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(s);
XmlNamespaceManager nsp = new XmlNamespaceManager(xmldoc.NameTable);
nsp.AddNamespace("soap","http://www.w3.org/2003/05/soap-envelope");
XmlNode node1 = xmldoc.DocumentElement;//.SelectSingleNode("Envelope",nsp);
XmlNode node2 = node1.SelectSingleNode("child::soap:Body", nsp);
configDocument.Load(xmlPath);
if (configDocument != null)
{
XmlNode root = configDocument.SelectSingleNode("descendant::Root");
……这样
XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xmldoc.NameTable);
xmlNamespaceManager.AddNamespace("soap", "http://www.w3.org/2003/05/soap-envelope");
xmlNamespaceManager.AddNamespace("ns", "http://tempuri.org/");
XmlNode node1 = xmldoc.SelectSingleNode("/soap:Envelope/soap:Body/ns:VerificationUserLoginResponse/ns:VerificationUserLoginResult", xmlNamespaceManager);
也可以直接查找:
XmlNode node1 = xmldoc.SelectSingleNode("//ns:VerificationUserLoginResult", xmlNamespaceManager);