Purpose
UPDATEXML() updates the node on the specified XPath in an XML string.
Syntax
UPDATEXML(xml_target, xpath_expr, new_xml)
Parameters
Note
Replace the portion specified by xpath_expr in xml_target with new_xml. If there are no or multiple matches for xpath_expr, the original content of xml_target is returned.
| Parameter | Description |
|---|---|
| xml_target | The XML string, which can be an XML document or fragment. |
| xpath_expr | The XPath expression of the node to be updated. |
| new_xml | The new XML fragment to replace the node. |
Return type
The return type is LONGTEXT.
Examples
Call the
UPDATEXML()function to replace the</a>node with<x>carrot</x>and return the updated XML string.<a/><b/>represents a root node with the<a>and<b>nodes.obclient [test_db]> SELECT UPDATEXML('<a/><b/>', '/a', '<x>carrot</x>');The return result is as follows:
+----------------------------------------------+ | UPDATEXML('<a/><b/>', '/a', '<x>carrot</x>') | +----------------------------------------------+ | <x>carrot</x><b></b> | +----------------------------------------------+ 1 row in setCall
UPDATEXML()to replace theanode under therootnode in the XML string with the<b>bbb<b>node and return the updated XML string.obclient [test_db]> SELECT UPDATEXML('<root><a>aaa</a></root>', '/root/a', '<b>bbb</b>');The return result is as follows:
+---------------------------------------------------------------+ | UPDATEXML('<root><a>aaa</a></root>', '/root/a', '<b>bbb</b>') | +---------------------------------------------------------------+ | <root><b>bbb</b></root> | +---------------------------------------------------------------+ 1 row in set