XML data in MySQL supports bitsCN.com.
Today, I want to introduce you to XPath, which is the language for navigation and querying XML documents. We start with a function.
UpdateXML () function
We have spent a lot of time introducing the ExtractValue () function, but have not introduced other XML functions of MySQL, such as UpdateXML (), because we previously mainly imported the data in the XML document into the MySQL database, UpdateXML () is a function that uses different XML tags to match and replace XML blocks.
ExtractValue () has two string parameters: an XML tag and an XPath expression.
ExtractValue (xml_frag, xpath_expr)
It returns the first text node that matches the XPath expression. Suppose you want to "To" And save the result to a variable. The following is how to use the UpdateXML () function to achieve this goal:
Mysql> SELECT @ new_xml_node: = UpdateXML ( ,
-> // City,
-> )
-> AS xml_node;
+ ----------------------------------------- +
| Xml_node |
+ ----------------------------------------- +
| |
+ ----------------------------------------- +
1 row in set (0.03 sec)
Mysql> SELECT @ new_xml_node;
+ ----------------------------------------- +
| @ New_xml_node |
+ ----------------------------------------- +
| |
+ ----------------------------------------- +
1 row in set (0.00 sec)
If no text node matching the expression is found, the original XML string is returned.
Mysql> SELECT @ new_bitsCN.com