读书人

请问:这样的XPath如何写

发布时间: 2012-03-14 12:01:12 作者: rapoo

请教:这样的XPath怎么写?
要查找的XML文件如下,我想用XPath把结果插入"root"节点,可是"/Test/Response/..."这种方法行不通,这是为什么,哪个达人给我讲讲吧,谢谢啦

XML code
<?xml version="1.0" encoding="utf-8"?><Test Handler="xml">  <Request>    <Execute>      <Command>        <Statement>        </Statement>      </Command>      <Properties>        <PropertyList>          <Catalog>YAP</Catalog>        </PropertyList>      </Properties>    </Execute>  </Request>  <Response>    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">      <soap:Body>        <ExecuteResponse xmlns="urn:schemas-microsoft-com:xml-analysis">          <return>            <root xmlns="urn:schemas-microsoft-com:xml-analysis:mddataset" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">            </root>          </return>        </ExecuteResponse>      </soap:Body>    </soap:Envelope>  </Response></Test>



[解决办法]
你的xml存在多个不同namespace而没有namespace prefix的结点,所以是不可以的。
你应该加个prefix就可以了。如

<soap:Body>
<a:ExecuteResponse xmlns:a="urn:schemas-microsoft-com:xml-analysis">
<return>
<am:root xmlns:am="urn:schemas-microsoft-com:xml-analysis:mddataset" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<am:/root>
</return>
</a:ExecuteResponse>
</soap:Body>

读书人网 >XML SOAP

热点推荐