XmlDocument.SelectSingleNode 和前缀 + xmlNamespace 问题 [英] XmlDocument.SelectSingleNode and prefix + xmlNamespace issue
本文介绍了XmlDocument.SelectSingleNode 和前缀 + xmlNamespace 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将以下字符串加载到 XML 文档中:
I have the following string loaded to an XML document:
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server</faultcode>
<faultstring>El cliente con los parámetros introducidos no existe./faultstring>
<detail>
<ns:ClienteWSDo29Exception xmlns:ns="http://services.do29.imq.es">
<Do29Exception xmlns="http://services.do29.imq.es" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ax211="http://model.do29.imq.es/xsd" xmlns:ax213="http://dto.do29.imq.es/xsd" xmlns:ax29="http://exception.do29.imq.es/xsd" xsi:type="ax29:Do29Exception">
<ax29:classname>class es.imq.do29.dao.ClienteDaoImpl</ax29:classname>
<ax29:trace xsi:nil="true" />
<ax29:previous xsi:nil="true" />
<ax29:method>getCliente</ax29:method>
<ax29:id>1</ax29:id>
<ax29:message>El cliente con los parámetros introducidos no existe.</ax29:message>
</Do29Exception>
</ns:ClienteWSDo29Exception>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
然后在xml中使用命名空间的情况下我尝试过:
Then following the case with namespaces in xml i tried:
XmlDocument xmldocu = new XmlDocument();
xmldocu.LoadXml(xml);
XmlNamespaceManager namespaces = new XmlNamespaceManager(xmldocu.NameTable);
namespaces.AddNamespace("ax29", "http://services.do29.imq.es");
XmlNode nodemsgx = xmldocu.SelectSingleNode("//message", namespaces);
XmlNode nodemsg = xmldocu.SelectSingleNode("//ax29:message", namespaces);
但是 nodemsgx 和 nodemsg 为空 :S 正确的做法是什么?我使用//message 因为我想获取该类型的任何节点而不是该节点的特定路径...
But nodemsgx and nodemsg are null :S Whats the correct way to do it? I used //message becouse i want to get any node of that type not the specific path to this node...
推荐答案
XML 文档中的 ax29
前缀设置为 "http://exception.do29.imq.es/xsd"
命名空间,而不是 "http://services.do29.imq.es"
.
The ax29
prefix in the XML document is set to the "http://exception.do29.imq.es/xsd"
namespace, not "http://services.do29.imq.es"
.
试试这个:
namespaces.AddNamespace("ax29", "http://exception.do29.imq.es/xsd");
XmlNode nodemsg = xmldocu.SelectSingleNode("//ax29:message", namespaces);
这篇关于XmlDocument.SelectSingleNode 和前缀 + xmlNamespace 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文