APImetrics

The APImetrics Developer Hub

Welcome to the APImetrics developer hub. You'll find comprehensive guides and documentation to help you start working with APImetrics as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

Parsing XML Content

Setting conditions on an API basis

Key Concepts

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.

XPath Syntax

We used standard XPath syntax.

Item
Description

tag

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.

[@attrib]

Selects all elements that have the given attribute.

[@attrib='value']

Selects all elements for which the given attribute has the given value. The value cannot contain quotes.

[tag]

Selects all elements that have a child named tag. Only immediate children are supported.

[tag='text']

Selects all elements that have a child named tag whose complete text content, including descendants, equals the given text.

[position]

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.

Selecting or validating a variable

<?xml version="1.0" ?>
<!--  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"

 [@date]|tag|lower 

Will either set a variable to ALL or return ALL.

So here we will return a PASS if ALL is detected.

Parsing XML Content

Setting conditions on an API basis