Skip to end of metadata
Go to start of metadata

Quite often a service returns data in the form of XML. Normally you would only need a portion of that XML in order to feed it to the next service in your workflow.

XPath is a major path in W3C’s XSLT (Extensible Stylesheet Language Transformations) standard. It is used to navigate through elements and attributes in an XML document. An XPath service in Taverna provides enhanced support for creating and executing XPath expressions over XML data in order to extract specific fragments (elements or attributes) from the XML data.

Tutorial

Taverna tutorial 2014: XPath and XML

Adding an XPath Service

  1. Expand Service templates under Available services in the Service Panel.
  2. Select XPath Service.
  3. Drag the XPath Service and drop it into the Workflow Diagram.
  4. In a dialog that pops up, configure the XPath Service as explained next.

Configuring an XPath Service

The XPath service provides an intuitive and easy-to-use way of creating XPath expressions. It does not require detailed knowledge of the XPath language – expressions can be generated by selection of relevant nodes in the tree-like view of the provided example XML data.

Example data can be an XML output that you know the service you are using to feed the XPath service will return.

To configure an XPath service:

  1. Copy and paste an example XML data that you want to feed into the XPath service.
  2. Click the green arrow button. This will generate the tree-like view of the example XML data. XML elements are tree nodes marked with the "< >" icon. Attributes are marked with the "@" icon.
  3. Select nodes on the tree that you want to extract from the XML. The XPath expression that corresponds to the selected nodes will appear in the Xpath expression box. 
  4. Click the Run XPath button to see what an example output would be.

Alternatively, you can enter the XPath expression directly in the XPath box without selecting nodes from the example XML.

You can also mix the two approaches - auto-generate the XML from the example data and then tweak the XPath expression.

Namespace handling

Sometimes XML data contains elements with the same name but which belong to a different namespace. The XPath service lets you create abbreviation for namespaces and can select elements that belong to a certain namespace.

To configure namespace mapping:

  1. Click the Show namespace mappings... link.
  2. Namespace mappings box will expand.

3. Click the Add Mapping button to add a mapping for a namespace from your XML data to its abbreviation that you want to use in the XPath expression.
4. Add as many mappings as you like.

5. Modify the XPath expression to use the namespace abbreviations.
6. Click the Run XPath button to see what an example output would be.

 

Labels
  • None