XPATH_STRING
Description
XPATH_STRING
is a row function that takes XML and returns the first string matching the given XPath expression.Syntax
XPATH_STRING
(xml_expression
,"xpath_expression
")Return Value
Returns one value per row of type
TEXT
. If the XPath expression matches more than one string in the given XML node, this function will return the
first
match only. To return all matches, use XPATH_STRINGS
instead.Input Parameters
- xml_expression
- Required. The name of a field of typeTEXTor a literal string that contains a valid XML node (a snippet of XML consisting of a parent element and one or more child nodes).
- xpath_expression
- Required. An XPath expression that refers to a node, element, or attribute within the XML string passed to this expression. Any XPath expression that complies to the XML Path Language (XPath) Version 1.0 specification is valid.
Examples
These example
XPATH_STRING
expressions assume you have a field in your dataset named address
that contains XML-formatted strings such as this:<list> <address type="work"> <street1>1300 So. El Camino Real</street1> <street2>Suite 600</street2> <city>San Mateo</city> <state>CA</state> <zipcode>94403</zipcode> </address> <address type="home"> <street1>123 Oakdale Street</street1> <street2/> <city>San Francisco</city> <state>CA</state> <zipcode>94123</zipcode> </address> </list>
Get the
zipcode
value from any address
element where the type
attribute equals home
:XPATH_STRING([address], "//address[@type='home']/zipcode")
returns:
94123
Get the
city
value from the second address
element:XPATH_STRING([address], "/list/address[2]/city")
returns:
San Francisco
Get the values from all child elements of the first address element (as one string):
XPATH_STRING([address], "/list/address")
returns:
1300 So. El Camino RealSuite 600 San MateoCA94403