XPath Queries

Action: XPath

Action-specific name/value pairs:

Parameter Name Description
DocumentName or DocumentOID The Name or OID of the document that is to be queried.

A value of * specifies all documents.

Add * to the end of the name to specify all documents whose name starts with the prefix preceding the *, eg: "test*"

Note: Use of the wildcard (*) feature requires Build 6 or later.

Document.[no].Name (standard HTTP input)

or

DocumentNames (JSON input)
Alternatively you can specify a list of document names to be searched by using this parameter instead of DocumentName or DocumentOID.

If you are using standard HTTP input, specify each name using a different value for [no], eg:

Document.1.Name=firstExample
Document.2.Name=secondExample

If you are using JSON input, specify each name as an array element of the DocumentNames parameter, eg:

DocumentNames:["doc1","doc2","doc3"]

Note: Use of this parameter requires Build 6 or later.

XPath The XPath Query to be used to search the specified document(s). Note that the XPath Query must be correctly URL-escaped if necessary.

eg: /doc/aaa/bbb

Note that XPath can be used to make very complex queries, eg: //bar[contains(@name,'ogan')][parent::*/@location = 'Town']

NodeList (Optional, JSON input only) Optional JSON-specific parameter. If set to true, a simple JSON array of matching NodeOIDs is returned. By default, NodeList is set to false and the full set of details about each matching node is returned in the JSON array.

Alternatively, the parameters above can be incorporated into a single JSON string and specified using the parameter name JSON, eg:

{DocumentName:"myExample",XPath:"/doc/aaa/bbb",NodeList:true}

If you're using Build 6 or later:

To specify all documents:

{DocumentName:"*",XPath:"/doc/aaa/bbb",NodeList:true}

To specify all documents whose names start with a particular prefix:

{DocumentName:"test*",XPath:"/doc/aaa/bbb",NodeList:true}

To specify a list of documents:

{DocumentNames:["firstDocument","secondDocument","thirdDocument"],XPath:"/doc/aaa/bbb",NodeList:true}

Example Request

Action=XPath
&DocumentName=myExample
&MDBAccessKeyId=[your access key id]
&Signature=[computed signature]
&SignatureMethod=HmacSHA256
&SignatureVersion=2
&Timestamp=2009-06-14T13%3A19%3A41
&Version=2009-04-15
&XPath=/doc/aaa/bbb
&db=mdbx"

or:

Action=XPath
&JSON=%7BDocumentName%3A%22myExample%22%2CXPath%3A%22/doc/aaa/bbb%22%2CNodeList%3Atrue%7D
&MDBAccessKeyId=[your access key id]
&OutputFormat=JSON
&Signature=[computed signature]
&SignatureMethod=HmacSHA256
&SignatureVersion=2
&Timestamp=2009-06-14T13%3A19%3A41
&Version=2009-04-15
&db=mdbx


Example Response

XML

<?xml version='1.0'?>
<XPathSelectResponse xmlns="http://mdbx.mgateway.com/doc/2009-06-05/">
   <XPathSelectResult>
      <Node>
         <NodeOID>
            5-7
         </NodeOID>
         <NodeType>
            1
         </NodeType>
         <TagName>
            bar
         </TagName>
      </Node>
      <Node>
         <NodeOID>
            5-11
         </NodeOID>
         <NodeType>
            1
         </NodeType>
         <TagName>
            bar
         </TagName>
      </Node>
   </XPathSelectResult>
</XPathSelectResponse>

Note that the information returned by M/DB:X depends on the type of nodes returned by the query. All XPath queries return pointers to matching nodes. Each node in the DOM has a unique NodeOID, and these are returned in the query results. M/DB:X will also return the Standard XML NodeType for each NodeOID.

If the Node is an Element (NodeType=1), then M/DB:X will also return the Element's TagName.

If the Node is an Attribute (NodeType=2), then M/DB:X will also return the Attribute's Name and Value.

Retrieval of this additional information is deliberate: the idea is to save making further REST requests to access the basic properties of the matching Nodes. However, other DOM API methods may be needed to gather the information relating to the query results.

JSON (ie if OutputFormat=JSON specified in the Request)

If NodeList is set to, or defaults to false:

[{NodeOID:"5-7",NodeType:1,TagName:"bar"},{NodeOID:"5-11",NodeType:1,TagName:"bar"}]

If NodeList is set to true:

["5-7","5-11"]