xml – 为什么简单的XPATH不起作用
发布时间:2020-12-16 22:55:01 所属栏目:百科 来源:网络整理
导读:我有一个 XML(在BizTalk中)看起来像 ns0:Provide xmlns:ns0="http1" xmlns:ns1="http2" xmlns:ns2="http://schemas.microsoft.com/2003/10/Serialization/" ns0:providerRequest ns1:Header ns1:OperationGet_RU_PatchData/ns1:Operation ns1:RequestIdf6bbe
我有一个
XML(在BizTalk中)看起来像
<ns0:Provide xmlns:ns0="http1" xmlns:ns1="http2" xmlns:ns2="http://schemas.microsoft.com/2003/10/Serialization/"> <ns0:providerRequest> <ns1:Header> <ns1:Operation>Get_RU_PatchData</ns1:Operation> <ns1:RequestId>f6bbeb27-1bfd-4d9c-90e4-d195baf8ca60</ns1:RequestId> <ns1:SendDate>2004-02-14T21:44:14</ns1:SendDate> <ns1:SenderSystemName>temperat iras</ns1:SenderSystemName> </ns1:Header> <ns1:Parameters> <ns1:Parameter> <ns1:Name>turbine corripuit</ns1:Name> <ns1:Value>regemque dedit</ns1:Value> </ns1:Parameter> </ns1:Parameters> </ns0:providerRequest> </ns0:Provide> 我试着获取参数中唯一参数的值. string(/*[local-name()='Provide' and namespace-uri()='http1']/*[local-name()='providerRequest' and namespace-uri()='http1']/*[local-name()='Parameters' and namespace-uri()='http2'][1]/*[local-name()='Parameter' and namespace-uri()='http2']/*[local-name()='Name']) 这个工作正常 string(/Provide/providerRequest/Parameters[1]/Parameter/Name) 什么都没给我?有没有办法不用命名空间创建这样的怪异语句? 解决方法
只需在XSLT文档中声明名称空间,然后您就可以使用:
string(/ns0:Provide/ns0:providerRequest/ns1:Parameters[1]/ns1:Parameter/ns1:Name) 通过查看本地名称,您可以有效地忽略命名空间 – 为什么首先添加它们呢? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |