JUnit Test if an XML document is sorted by an arbitrary column

Given an XML document e.g.

<root>
  <row>
    <a>2</a>
    <b>1</b>
    <c>8</c>
  </row>
  <row>
    <b>5</b>
    <a>2</a>
    <c>8</c>
  </row>
  <row>
    <a>2</a>
    <c>8</c>
    <b>6</b>
  </row>
</root>

Is there an easy way to claim that an XML document is sorted by element B in XMLUnit

Edit: I have a strange problem with a piece of software that I cannot change, where the value of the XML tags in any given node should be in a specific order. I would like my test conductor to apply this set of rules before any other check.

+3
source share
3 answers

Use the value of the following simple XPath 1.0 expression :

not(//b[. > following::b])

+2
source

XPath.

, XPath /root/row/b, NODESET, node List. , "" , Arrays.asList() ( , Java).

+1

If you can execute XQuery, then the XQuery statement:

every $i in (1 to count ($x/row) - 1)
satisfies 
   let $j :=  $i + 1   
   return number($x/row[$i]/b) <= number($x/row[$j]/b)

where $ x is the document, is true if the lines are in ascending order of b, false otherwise

+1
source

Source: https://habr.com/ru/post/1742880/


All Articles