XMLExtractValue() function
The XMLExtractValue() function extracts the actual (scalar) value from an XML object that you specify by using the XPath parameter. The result of the XPath query must be a single node and must be an element, a text node, or an attribute.
If you want a specific data type, you can wrap the XMLExtractValue() function with a conversion function, such as a function that converts the varchar to a date.
Syntax
varchar = XMLExtractValue(XML input, varchar XPath);
The input value
specifies an XML file.
The XPath value specifies an XPath query.
Returns
If the result is an element, it must have a single text node as its child; the child node provides the text content for the scalar return value. If the node does not exist, the function returns null. If the XPath expression returns more than one node or if the expression points to an element node with anything other than a single text child node, the function returns an error.
Example
SELECT XMLExtractValue(object_value,'/PurchaseOrder/Reference')
"REFERENCE"
FROM PURCHASEORDER
WHERE
XMLExistsNode(object_value,'/PurchaseOrder[SpecialInstructions=“Rush“]
') = 1;
JSMITH-20021009123336271PDT
ABELL-20021009123336321PDT
JDOE-20021009123337303PDT
GWASHINGTON-20021009123337123PDT