0

i am trying to verify a xml structure, where i want to check that the ns22:statement true tag is found after the postcode DataItem.

<ns21:DataItem name="country" default="false" />
<ns21:DataItem name="postcode" default="false">
    <ns22:statement disabled>true</ns22:statement>
</ns21:DataItem>

I have tried this

(?m)\b.*:DataItem name="postcode" (?s)\b.*>$\n.*\bstatement disabled>true\b

but when changing postcode to country (where is supposed not to return anything) it catches all tags country, postcode and statement true.

I have also created this https://regexr.com/3quso

Any suggestions of how to get only the postcode+statement true??

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Konstantinos
  • 3
  • 2
  • 5

1 Answers1

0

XPath really does look like the best tool for the job given you're trying to validate XML structure as well as content. So, ignoring namespaces, you could use the following XPath in a soapUI XPath Match assertion:

boolean(//*[local-name()='DataItem'][@name='postcode']/*[local-name()='statement' and .='true'])

enter image description here

Also, in <ns22:statement disabled>true</ns22:statement>, is disabled meant to be part of the element name or an attribute? As it stands, it makes the XML invalid, so I've ignored it.

For good reasons not to use regular expressions to parse XML/HTML, see Why it's not possible to use regex to parse HTML/XML: a formal explanation in layman's terms

craigcaulfield
  • 3,381
  • 10
  • 32
  • 40