【问题标题】:xpath expression to get namespace uri获取命名空间uri的xpath表达式
【发布时间】:2018-09-14 10:25:12
【问题描述】:

我想提取以下xml的“输出元素”(-->http://Customer_LIB/bo/getCustomer/v1)的命名空间:

<?xml version="1.0" encoding="UTF-8"?>
<result xsi:type="cu:getCustomerResponseMsg" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cu="wsdl.http://Customer_LIB/Customer" xmlns:cu_1="http://Customer_LIB/Customer" xmlns:v1="http://Customer_LIB/bo/getCustomer/v1">
 <cu_1:getCustomerResponse>
    <output xsi:type="v1:GetCustomerResponse">
      <firstName>Hans</firstName>
      <lastName>Moser</lastName>
    </output>
  </cu_1:getCustomerResponse>
</result>

有没有人有想法。我已经尝试过多种表达方式。请考虑我只能使用 Xpath 1.0 进行提取。非常感谢。

使用 xpath 1.0 表达式来检查 xml 中是否使用了命名空间“http://Customer_LIB/bo/getCustomer/v1”也足够了。

【问题讨论】:

    标签: xml xpath


    【解决方案1】:

    使用这个:

    xmlstarlet sel -t -v '//result/namespace::*[2]' file
    

    xmlstarlet sel -t -v '//result/namespace::*[contains(name(), "v1")]' file
    

    输出

    http://Customer_LIB/bo/getCustomer/v
    

    【讨论】:

    • 是否也可以检查 xml 是否包含具有 value="Customer_LIB/bo/getCustomer/v1" 的命名空间我尝试使用以下 xpath 值 '//result/namespace::*[contains(namespace-uri( ), "v1")]' 但我失败了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    相关资源
    最近更新 更多