XPath expressions are used in orchestrations and flat file schema definitions when you need to identify one or more nodes in a message or variable in order to access data or determine whether a condition has been met.
XPath is an XML standard that defines a grammar to identify nodes or sets of nodes (called node sets) in XML documents.
You can edit the default XPath expressions, generated in the following panes:
XPath 2.0 is supported.
XPath describes the location of XML elements and attributes as a path similar to URLs or directories on your local file system. Each element or attribute is a node in a tree that begins with the root node. The root node contains the entire tree, so any node within the tree can be found by following a path down the branches.
The basic syntax is:
/root-node/child-node/.../final-element-node/root-node/child-node/.../final-element-node/@attribute-node
You determine this path from the XML Schema that describes the messages.
XPath uses the @ symbol as a shorthand to identify attributes. Paths without @, or the attribute:: prefix, identify elements by default. For example:
/PackingSlip/PONumber/Itemidentifies the Item element found inside PONumber in the PackingSlip root node.
Node names can also appear with namespaces, such as tns:OrderNumber or *:Item. The portion of the name up to the colon is a prefix identifying a namespace and the colon is the delimiter between the namespace and the node's local name.
Namespaces are an XML standard used to uniquely identify elements or attributes when documents share content from several schemas. WebSphere® Cast Iron Studio automatically assigns and manages namespaces for the XML Schemas used in configuration documents.
You might occasionally want to select a node only if some condition is met. These selection conditions are known as predicates.
You define predicates inside brackets, such as:
/PV1/PatientDepartment[text()='Nursery']This expression selects the PatientDepartment node only if the data in the node is Nursery.
/Order/OrderDetail/Item[5]This expression selects the fifth Item node within OrderDetail.
XPath expressions can also be boolean conditions that evaluate to true or false. These expressions can be used to select specific nodes or simply to identify a condition that must be met. You can use the Expression Builder to help you define conditions. XPath operators that can appear in expressions include:
concat('New Order # ',/Orders/Order/OrdNumber)
count(/Orders/Order)
normalize-space(/Job/Address/Line1)
string(/PurchaseOrder/VendorID)
translate(/Issue/ShortDescr,
'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
For a complete list of XPath functions, see the XPath Specification ( http://www.w3.org/TR/xpath).
You can test your XPath Expressions against XML test data using the XPath Evaluator.