0

I have the following xml:

<myRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:ben”>
  <myDefinition>
    <name>Value1</name>
    <version>Value2</version>
  </myDefinition>
  <myHeader>
    <id>52452519-4765-4b68-b632-01913c3d3948</id>
    <creationTime>2018-07-04T10:51:56</creationTime>
    <target>
      <myCode>value3</myCode>
    </target>
  </myHeader>
</myRequest>

I am looking to check the text between name element is 'Value1', text between version is 'Value2' and text between myCode is 'Value3'.

How can I check these values in a single xpath query?

eVolve
  • 1,340
  • 1
  • 11
  • 30
  • What do you mean by *"check values"*? Share your current XPath and desired output – Andersson Jul 09 '18 at 08:44
  • So I have an element Value1 and I want to assert that "Value1" is the text between the name tags. In the same query I also want to check "value3" is between the follow element value3 etc – eVolve Jul 09 '18 at 08:48

1 Answers1

1

If you want to select myRequest that meet following requirements:

  • contains name descendant with text "Value1"
  • contains version descendant with text "Value2"
  • contains mycode descendant with text "Value3"

try below XPath:

/myRequest[myDefinition[name="Value1" and version="Value2"] and myHeader[target/myCode="Value3"]]
Andersson
  • 51,635
  • 17
  • 77
  • 129
  • @Benl2 , any feedback? – Andersson Jul 09 '18 at 13:33
  • 1
    Good (+1), but OP will also have to fix the closing script quote in the XML (has to be normal double quote) and then account for the default namespace: `xmlns="urn:ben”`. See [***How does XPath deal with namespaces?***](https://stackoverflow.com/q/40796231/290085) – kjhughes Jul 09 '18 at 16:30