gpt4 book ai didi

xml - 为什么简单的 XPATH 不起作用

转载 作者:数据小太阳 更新时间:2023-10-29 02:07:00 27 4
gpt4 key购买 nike

我有一个 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)

什么都没给我?有没有办法不使用 namespace 创建这种可怕的语句?

最佳答案

根据您的 XPath 实现,您可以使用快捷方式注册 XML 命名空间,以便您可以像那样编写 XPath 表达式(假设您将 http1 注册为 h1http2 作为h2

string(/h1:Provide/h1:providerRequest/h2:Parameters[1]/h2:Parameter/h2:Name)

关于xml - 为什么简单的 XPATH 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7416465/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com