Joezi
Joezi

Reputation: 55

xpath expression to get namespace uri

I would like to extract the namespace of the "output-element" (--> http://Customer_LIB/bo/getCustomer/v1) of the following xml:

<?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>

Does anyone have an idea. I have already tried diverse expressions. Please consider that I can only use Xpath 1.0 for extraction. Many thanks in advance.

It would also be sufficient to have a xpath 1.0 expression to check if namespace "http://Customer_LIB/bo/getCustomer/v1" is used in xml.

Upvotes: 2

Views: 412

Answers (1)

Gilles Qu&#233;not
Gilles Qu&#233;not

Reputation: 185219

Use this :

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

or

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

Output

http://Customer_LIB/bo/getCustomer/v

Upvotes: 1

Related Questions