Searching XML Values
Learn about the interesting properties of an XML value.
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 access specific elements or attributes within an XML document (i.e., an XML value). It provides a path-like syntax that allows us to define the location of the desired XML nodes with precision and flexibility.
For demonstration purposes, let’s consider a subset of the book catalog from one of our running examples again:
Get hands-on with 1400+ tech skills courses.