Selecting XML elements by using XPath expressions (2024)

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.

Selecting XML elements by using XPath expressions (1)

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.

Selecting XML elements by using XPath expressions (2)

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.

Selecting XML elements by using XPath expressions (3)

Example:evaluating XPath with unique values

Selecting XML elements by using XPath expressions (4)

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.

Selecting XML elements by using XPath expressions (5)

Example:evaluating the XPath

How to limit XML nodes in Modules by using XPath expressions

Define XPath expressions on the XML document and XMLelement 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.

Selecting XML elements by using XPath expressions (6)

XPath - parameter

Selecting XML elements by using XPath expressions (2024)
Top Articles
Latest Posts
Article information

Author: Trent Wehner

Last Updated:

Views: 6173

Rating: 4.6 / 5 (76 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Trent Wehner

Birthday: 1993-03-14

Address: 872 Kevin Squares, New Codyville, AK 01785-0416

Phone: +18698800304764

Job: Senior Farming Developer

Hobby: Paintball, Calligraphy, Hunting, Flying disc, Lapidary, Rafting, Inline skating

Introduction: My name is Trent Wehner, I am a talented, brainy, zealous, light, funny, gleaming, attractive person who loves writing and wants to share my knowledge and understanding with you.