XPath expressions
USE:
XPath expressions are used to operate on XML messages.
- for XPath syntax guidelines, check w3schools.com
- for testing expressions: XPath and Flat File see Int4 IFTT Expression Test Tool
Please note that all XPATH expressions that point to the node values should be ended with /text(), while the expressions that point to Attribute value should be ended just with attribute name.
All variables XPath expressions should refer to values, not nodes.
EXAMPLES:
Example 1:
Sample XML for which the expressions will be presented:
<?xml version="1.0" encoding="UTF-8"?>
<DELVRY07>
<IDOC BEGIN="1">
<E1EDL20 SEGMENT="1">
<VBELN>TEST0080018016</VBELN>
<VSTEL>3000</VSTEL>
<VKORG>3000</VKORG>
<E1EDL22 SEGMENT="1">
<VSTEL_BEZ>SBC: Shipping Point New York</VSTEL_BEZ>
<VKORG_BEZ>USA Philadelphia</VKORG_BEZ>
<INCO1_BEZ>Costs, insurance & freight</INCO1_BEZ>
<ROUTE_BEZ>Northern Route</ROUTE_BEZ><VSBED_BEZ>Standard</VSBED_BEZ>
</E1EDL22>
</E1EDL20>
</IDOC>
<DELVRY07>
//E1EDL20/VBELN/text() points just to field value. The different value will be allowed
//E1EDL20/VBELN points to a node so will allow that node will exist in reference or current run and will be missing in another
//E1EDL20 points to the node and all subnodes, values and attributes
//IDOC/@BEGIN points to the attribute and its value
You can also look for nodes by entering conditions like for example:
//E1EDK03[IDDAT='001']/UZEIT/text() to find a field UZEIT from node E1EDK03 where other field in this node, IDDAT will contain value '001'
//*:E1EDK03/UZEIT/text() - to find a field UZEIT from node E1EDK03 - if it would have an unknown prefix
Example 2:
Another example is ignoring the XML namespace, for example, if you would like to compare the execution of enterprise service on different environments. Sample XML:
<?xml version="1.0" encoding="UTF-8"?>
<n0:ServiceOrderQuotationCRMByIDResponse_sync xmlns:n0="http://sap.com/xi/CRM/SE" xmlns:prx="urn:sap.com:proxy:OC1:/1SAI/TASC5D32AE048B38AAA2236:740" xmlns:n1="urn:customer.com:A:HYBRIS:eCommerce">
<ServiceOrderQuotation>
....
and we would like to ignore the xmlns:prx namespace, then XPath expression should look like the following:
//n0:ServiceOrderQuotationCRMByIDResponse_sync/@prx
Example 3:
In this example, the message contains the default namespace but without the prefix:
<PostInvoice xmlns='http://www.invoicemonitor.com/webservices/posting/v1.1' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<transferId>72312355</transferId>
to read transferId value, the expression looks following:
//*:PostInvoice/transferId/text() or
/*[local-name()="PostInvoice"]/transferId/text()
We provided some examples for non-XML payloads (like EDIFACT) on this page.
It is possible to combine more than one expression in Variable Processing settings using '||' operator. Each sub-expression separated with '||' is evaluated separately, and the result is combined.
E.g. it is possible to configure variable PURCHASE_ORDER with following expression: //ns0:PurchaseOrder/@PurchaseOrderNumber||//ns0:PurchaseOrder/Header/Number/text()
During runtime, values from both PurchaseOrderNumber attribute and Number node will be stored in the variable.
© 2017 - 2022 Int4 AG All rights reserved