XPath Property
Provides a way to point to a specific element in the response.
Syntax
[VB.NET] Public Property XPath As String
[C#] public string XPath {get; set;}
Remarks
This property provides a way to point to a specific element in the response. This property implements a subset of the XML XPath specification, allowing you to point to specific elements in the XML documents.
The path is a series of one or more element accessors separated by '/'. The path can be absolute (starting with '/') or relative to the current XPath location.
The following are possible values for an element accessor:
'name' | A particular element name. |
[i] | The i-th subelement of the current element. |
.. | the parent of the current element. |
BuildDOM must be set to True prior to parsing the document for the XPath functionality to be available.
Example (Setting XPath)
Document root RestControl.XPath = "/" Specific Element RestControl.XPath = "/root/SubElement1/SubElement2/" i-th Child RestControl.XPath = "/root/[i]"
For JSON data, this will be the path to a specified value within the document. Since arrays in JSON only contain values, and no associated object name, an empty name will be used for these values. Thus, to reach an array element at position 1, the path must be set to "[1]". In addition, a root element named "json" will be added to each JSON document in the parser. Following is an example:
Simple JSON document
{ "firstlevel": { "one": "value", "two": ["first", "second"], "three": "value three" } }Example (Setting JSON XPath)
Document root RestControl.XPath = "/" Specific Element RestControl.XPath = "/json/firstlevel/one/" i-th Child RestControl.XPath = "/json/firstlevel/two/[i]/"
Default Value
""