xml - 获取命名空间uri的xpath表达式

标签 xml xpath

我想提取以下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 表达式来检查命名空间“http://Customer_LIB/bo/getCustomer/v1”是否在 xml 中使用也足够了。

最佳答案

用这个 :

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 - 获取命名空间uri的xpath表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52330017/

相关文章:

Photoshop 中的 Android 布局

c# - 如何根据其父节点的属性值查询XML节点

ruby - Nokogiri 和 XPath 帮助

xml - 除了使用扩展之外,如何在 XSLT 中处理自定义命名空间?

c# - 使用网络服务的 HTTP POST

Java + XML 问题

html - 每次更新站点地图都需要提交给搜索引擎吗?

xpath php 属性不起作用?

java - 仅匹配命名空间中的 XML 节点,而不知道 NS 前缀

java - Camel ..使用xpath解析消息正文中的xml