- Categories:
Semi-structured Data Functions (Parsing)
CHECK_XML¶
Checks the validity of an XML document. If the input string is NULL or a valid XML document, the output is NULL. In case of an XML parsing error, the output string contains the error message.
- See also:
Syntax¶
CHECK_XML( <string_containing_xml> [ , <disable_auto_convert> ] )
Arguments¶
Required:
string_containing_xml
This expression should evaluate to a VARCHAR. The VARCHAR should contain valid XML.
Optional:
disable_auto_convert
Specify the same value that you pass to the PARSE_XML function.
Default:
FALSE
Returns¶
The data type of the returned value is VARCHAR.
Examples¶
Show the Output of the Function When the XML is Valid¶
SELECT CHECK_XML('<name> Valid </name>');
+-----------------------------------+
| CHECK_XML('<NAME> VALID </NAME>') |
|-----------------------------------|
| NULL |
+-----------------------------------+
Show the Output of the Function When the XML is Invalid¶
SELECT CHECK_XML('<name> Invalid </WRONG_CLOSING_TAG>');
+--------------------------------------------------+
| CHECK_XML('<NAME> INVALID </WRONG_CLOSING_TAG>') |
|--------------------------------------------------|
| no opening tag for </WRONG_CLOSING_TAG>, pos 35 |
+--------------------------------------------------+
Locate Records With Invalid XML¶
SELECT xml_str, CHECK_XML(xml_str)
FROM my_table
WHERE CHECK_XML(xml_str) IS NOT NULL;