Purpose
This function is used to update the content of a node specified by a path in an XML string.
Syntax
UPDATEXML(xml_target, xpath_expr, new_xml)
Parameters
Note
Replace the part of xml_target specified by xpath_expr with new_xml. If xpath_expr does not match any result or matches multiple results, return the original result of xml_target.
| Field | Description |
|---|---|
| xml_target | The specified XML string, which can be an XML document or fragment. |
| xpath_expr | The path (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
Use the
UPDATEXMLfunction to replace the</a>node in the XML string with the<x>carrot</x>node and return the updated XML string.<a/><b/>represents a root node containing two nodes,<a>and<b>.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 setUse the
UPDATEXMLfunction 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
