XPath expressions for filtering output

You can use an XPath expression to filter the XML output returned by a common SQL API stored procedure.

To filter the output, specify a valid XPath query string in the xml_filter parameter of the procedure. The following restrictions apply to the XPath expression that you specify:

  • The XPath expression must reference a single value.
  • The XPath expression must always be absolute from the root node. For example, the following path expressions are allowed: /, nodename, ., and ... The following expressions are not allowed: // and @
  • The only predicates allowed are [path='value'] and [n].
  • The only axis allowed is following-sibling.
  • The XPath expression must end with one of the following, and, if necessary, be appended with the predicate [1]: following-sibling::string, following-sibling:: data, following-sibling::date, following-sibling::real, or following-sibling::integer.
  • Unless the axis is found at the end of the XPath expression, it must be followed by a ::dict, ::string, ::data, ::date, ::real, or ::integer, and if necessary, be appended with the predicate [1].
  • The only supported XPath operator is =.
  • The XPath expression cannot contain a function, namespace, processing instruction, or comment.
Tip: If the stored procedure operates in complete mode, do not apply filtering, or a SQLCODE (+20458) is raised.

For better control over processing the XML document returned in the xml_output parameter, you can use the XMLPARSE function available with Db2® pureXML®.

Example

The following XPath expression selects the value for the Data Server Product Version key from an XML output document:

 /plist/dict/key[.='Data Server Product Version']following-sibling::string[1]

The procedure returns the string 8.1.0.356 in the xml_output parameter. Therefore, the procedure call returns a single value rather than an XML document.