With an API that returns XML content, we can parse, manipulate and extract items from the XML either for a validation check in a specific test or as part of a workflow.
We used standard XPath syntax.
Selects all child elements with the given tag.
For example, spam selects all child elements named spam, and spam/egg selects all grandchildren named egg in all children named spam.
Selects all child elements.
For example, */egg selects all grandchildren named egg.
Selects the current node. This is mostly useful at the beginning of the path, to indicate that it’s a relative path.
Selects all subelements, on all levels beneath the current element.
For example, .//egg selects all egg elements in the entire tree.
Selects the parent element.
Selects all elements that have the given attribute.
Selects all elements for which the given attribute has the given value. The value cannot contain quotes.
Selects all elements that have a child named tag. Only immediate children are supported.
Selects all elements that have a child named tag whose complete text content, including descendants, equals the given text.
Selects all elements that are located at the given position. The position can be either an integer (1 is the first position), the expression last() (for the last position), or a position relative to the last position (e.g. last()-1).
How the selector works
The selector returns the FIRST matching element, after that it treats the rest of the result like it would a JSON structure, and anything after the ] is handled by the JSON parser.
<!-- A SAMPLE set of slides --> <slideshow author="Yours Truly" date="Date of publication" title="Sample Slide Show"> <!-- TITLE SLIDE --> <slide type="all"> <title>Wake up to WonderWidgets!</title> </slide> </slideshow>
To verify that the slide type is "ALL"
Will either set a variable to ALL or return ALL.
So here we will return a PASS if ALL is detected.