1

I have this bit of XML, where I need to find the element <urn:bpInstance> in order to transfer a value to it (for a SoapUI test):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:xxx:yyy:zzz">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:GetTaxInfo>
         <urn:bpInstance/>
         <urn:Id>Test123</urn:AncinitetsId>
         <urn:CprNumber>123456-7890</urn:CprNummer>
         <urn:FromYear>2015</urn:FraAarstal>
         <urn:ToYear>2021</urn:TilAarstal>
      </urn:GetTaxInfo>
   </soapenv:Body>
</soapenv:Envelope>

There might be changes in the structure, so I would prefer to find it by name alone. The name will remain the same and is unique.

My first attempt was to use //urn:bpInstance but that gives me the following error:

XPath syntax error at char 16 in {//urn:bpInstance}: Prefix urn has not been declared]

So based on this post I tried a work around where I used name()='urn:bpInstance' instead. This does not give any errors, but it doesn't catch any elements.

The expression is applied through the SoapUI user interface, so exactly how is evaluated is unclear. You can see it in the screenshot below. It's the Target that I'm struggling with.

Screenshot from SoapUI where the id should be transferred from one step to another.

How do I get the element <bpInstance> using XPath?

Jakob Busk Sørensen
  • 5,599
  • 7
  • 44
  • 96
  • Are you using any language to apply an XPath expression? – Yitzhak Khabinsky Mar 16 '21 at 13:41
  • @YitzhakKhabinsky good question. I am using SoapUI - a user interface for working with SOAP web services. I am trying to set up a test, where I transfer the id from the initialise call to the actual request call. So I don't know exactly how it is applied, as it is done via SoapUI. – Jakob Busk Sørensen Mar 16 '21 at 13:49
  • (1) Clean up your XML -- it has many unmatched start tags. XPath is defined over (well-formed) XML only. (2) Research how to declare namespace prefixes in SoapUI, declare needed namespace prefixes, and use them in XPath as usual. (3) If SoapUI does not support namespaces, use the normal workaround in XPath as stated in duplicate link. In your case: `//*[local-name() = "bpInstance" and namespace-uri()="urn:xxx:yyy:zzz"]` will select `urn:bpInstance` as requested. – kjhughes Mar 16 '21 at 14:41
  • I have done #2 for you and added a **SoapUI** entry to the [canonical Q/A for XML namespaces in XPath](https://stackoverflow.com/q/40796231/290085) – kjhughes Mar 16 '21 at 15:10

0 Answers0