Selecting XML elements by using XPath expressions

Use DotNet XPath expressions in TestCases to select elements in an XML resource.

Define XPath expressions in Modules to limit the nodes of an XML file.

Click here for a more detailed documentation on how to define XPath expressions.

Please note that node or attribute values must be specified with single quotes in XPath expressions.

Special characters in XPath expressions must be specified with a leading escape character.

XPath expressions in TestCases

The Module Evaluate XPath allows you to evaluate XPath expressions and to verify or buffer the result.

This Module is part of the Standard subset. You can find it under Standard modules->TBox XEngines->XML.

The content of the books.xml file which was loaded into the resource xmlResource, needs to be verified. The expression specified under XPath Expression is analyzed and compared to the value specified under Evaluation Result.

The system verifies for the book with the id 'bk002' in the books.xml file whether the value of the node author is Poet.

Example: evaluating XPath with unique values

The content of the books.xml file which was loaded into the resource xmlResourceToVerify, needs to be verified. The expression specified under XPath Expression is analyzed and compared to the value specified under Evaluation Result. The system verifies whether 2 book entries exist in the books.xml file.

Example: evaluating the XPath

How to limit XML nodes in Modules by using XPath expressions

Define XPath expressions on the XML document and XML element level in order to limit the nodes of an XML file.

  1. Go to the details view of the according ModuleAttribute and create the transition parameter XPath manually. Enter the XPath expression as value.

    Any XPath expressions which return XML elements are valid. For all other XPath expressions use the XModule chapter "XPath expressions in TestCases", for instance for the count function.

  2. Create the configuration parameter Transition manually and define the following value for this parameter: XPathToXmlElement.

XPath - parameter