- Categories:
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.
SyntaxÂļ
CHECK_XML( <string_containing_xml> [ , <disable_auto_convert> ] )
CHECK_XML( STR => <string_containing_xml>
[ , DISABLE_AUTO_CONVERT => <disable_auto_convert> ] )
ArgumentsÂļ
Required:
string_containing_xml
. OR .STR => string_containing_xml
Specify an expression that evaluates to a VARCHAR value that contains valid XML.
Optional:
disable_auto_convert
. OR .DISABLE_AUTO_CONVERT => 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.
Usage notesÂļ
You must either specify all arguments by name or by position. You canât specify some of the arguments by name and other arguments by position.
When specifying an argument by name, you canât use double quotes around the argument name.
ExamplesÂļ
The following examples use the CHECK_XML function.
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;