我想提取以下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/