UPDATEXML
Description
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
info
The xpath_expr parameter specifies the part of the xml_target parameter to be replaced with the new_xml parameter. If xpath_expr does not match any result or matches multiple results, the original result of xml_target is returned.
| Field | Description |
|---|---|
| xml_target | The XML string to be updated. It can be an XML document or fragment. |
| xpath_expr | The XPath expression that specifies the path of the node to be updated. |
| new_xml | The new XML fragment to be used to replace the node. |
Return type
LONGTEXT
Examples
-
Use the
UPDATEXMLfunction to replace the</a>node with the<x>carrot</x>node in the XML string and return the updated XML string. The<a/><b/>indicates a root node that contains two nodes,<a>and<b>.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 set (0.001 sec) -
Use the
UPDATEXMLfunction to replace theanode under therootnode with the<b>bbb</b>node in the XML string and return the updated XML string.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 (0.001 sec)