XPath Property
Provides a way to point to a specific element in the response.
Syntax
googledrive.getXPath([callback]) googledrive.setXPath( XPath, [callback])
Default Value
""
Callback
The 'callback' parameter specifies a function which will be called when the operation completes (or an error is encountered). If the 'callback' parameter is not specified, then the method will block and will not return until the operation completes (or an error is encountered).
The callback for the getXPath([callback]) method is defined as:
function(err, data){ }
'err' is the error that occurred. If there was no error, then 'err' is 'null'.
'data' is the value returned by the method.
The callback for the setXPath([callback]) method is defined as:
function(err){ }
'err' is the error that occurred. If there was no error, then 'err' is 'null'.
'err' has 2 properties which hold detailed information:
err.code err.message
Remarks
This property allows you to point to specific elements in the JSON documents. 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.
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.
Simple JSON document
{ "firstlevel": { "one": "value", "two": ["first", "second"], "three": "value three" } }Example (Setting JSON XPath)
Document root | JsonControl.XPath = "/" |
Specific Element | JsonControl.XPath = "/json/firstlevel/one/" |
i-th Child | JsonControl.XPath = "/json/firstlevel/two/[i]/" |
Data Type
String