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:

PARSE_XML

Syntax

CHECK_XML( <string_expression> )

Arguments

string_expression

An expression that evaluates to a VARCHAR.

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;
Back to top