Searching XML Values
Explore how to use MySQL's ExtractValue() function to search and extract specific XML values with XPath expressions. Understand XPath syntax, element selection, filtering, and learn to navigate XML data effectively within MySQL despite the lack of native XML support.
We'll cover the following...
MySQL does not offer native support for XML like it does for JSON. That is, there is no dedicated data type that represents XML, unlike there is with JSON. However, the database management system still readily provides two functions specifically dedicated to XML: ExtractValue() and UpdateXML(). As their names suggest, the former function searches an XML value, while the latter is useful for updating an XML value. Naturally, we start with a closer look at ExtractValue() to better understand swiftly accessing interesting XML value properties.
The XPath notation
ExtractValue(xml_value, xpath_expression) takes two arguments: xml_value and xpath_expression. The former represents the XML value to search, while the latter parameter takes an XPath expression that the function matches against the given XML value. Hence, before looking into the behavior of ExtractValue() itself, let’s explore the nature of XPath expressions.
XPath notation is a powerful and versatile language used to navigate and ...