The executeXPath Deluge task executes an XPath in the context of the specified XML and returns the value as a string. Here, XPath refers to the XML Path Language for finding information in an XML document. XML documents can be represented as a tree and XPath provides the ability to navigate this tree by selecting nodes by a variety of criteria. For example, in the following XML document,
- the XPath bookstore/book/title, selects all the title elements that are children of bookstore
- the XPath bookstore/book/title/text(), selects the text from all the title nodes
- the XPath bookstore/book/title, selects only the title of the first book node under the bookstore element
- the XPath bookstore/book[price>35]/price, selects all the price nodes with a price higher than 35
<?xml version="1.0" encoding="ISO-8859-1"?>
<title lang="en">Femat's Enigma</title>
<title lang="en">Survival Is Not Enough</title>
<title lang="en">The God Delusion</title>
<title lang="en">The Black Swan</title>
<author>Nassim Nicholas Taleb</author>
<variable> = <xml/string-variable>.executeXPath(<xpath>)
<variable> - the variable to hold the string value returned by the execute task.
<string/xml variable> - variable of type XML/string that holds the XML/JSON document
<xpath> - the xpath expression to select the specific nodes in an XML document.
To add the Execute XML task using Script Builder,
- Drag-n-drop the XML Manipulation - ExecuteXPath task from the left-side task tree.
- Define the variable to hold the string response from the Execute XPath task.
- Specify the string/xml variable that holds the xml/json document.
- Specify the xpath expression for finding the required information from the xml/json document. Use the XPath Learner to find the right xpath expression to be executed.
- Click Done to add the value to the script editor, as shown in the screen-shot given below:
The XPath Builder provides an intuitive user interface to find the required XPath expression from a given XML/ JSON File. The builder automatically converts JSON to XML so that XPath can be applied to it to filter nodes. To find XPath expressions,
- Click on theXPath Builder link. The Load dialog provides the option to specify the url of the XML/JSON file or upload the file from your PC or just copy-paste the file to the text-area of the builder. In the screen-shot given below, the URL of the XML file from the twitter.com site is specified. If the request method is GET, the HTTP GET request is used to get data from the url. If the request method is POST, the HTTP POST request is used to get data from the url. The parameter name and value must be passed as arguments, if any, to the POST method.
- On specifying the URL(as shown in the screenshot) or uploading the file, click Done to display the XML in tree format.
- The tree format of the XML gets loaded on the left-side of the XPath builder, as shown in the screen-shot below. The tab named XML Node Tree displays the XML in tree format. The tab named XML Content displays the content of the XML document. You can select any node in the tree and see the XPath expression getting generated for it in the Write XPath text area. For example, in the screen-shot given below, we have selected statuses/status/location/text(), which displays the text of all the location nodes in the xml document.
- The XPath of the selected node is displayed as shown below:
- You can also filter the nodes according to some criteria. (i.e. specify predicates)
- Click on the Execute button to apply the XPath expression on the XML file and view the results, as shown in the screen-shot below. Click on Apply to add the xpath expression to the Execute XMLdialog.
- In Xpath builder, external entity in xml content cannot be processed.