- 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;