This code sample specifies the 'xmlerror= message' option in the xmlparse call. This will store the parsed XML for XML documents that are valid XML, and store a parsed XML error message element for documents that are not valid XML.
insert xmlxfsTab(filename , content) select 'ParsedDir/'+filename , xmlparse(content option 'xmlerror = message') from xmlxfsTab -------------- (4 rows affected)
The following code sample applies the xmlextract built-in function on parsed data and gets the list of non-XML data, along with exception message information.
select filename , xmlextract('/xml_parse_error', content)
from xmlxfsTab
where '/xml_parse_error' xmltest content and filename like 'ParsedDir%'
----------------
Or with xmlrepresentation builtin
select filename , xmlextract('/xml_parse_error', content)
from xmlxfsTab
where xmlrepresentation(content) = 0
and '/xml_parse_error' xmltest content
filename
----------------------------------
ParsedDir/picture.jpg
<xml_parse_error>An exception occurred!
Type:TranscodingException,
Message:An invalid multi-byte source text sequence was
encountered</xml_parse_error>
ParsedDir/nonxmldoc.txt
<xml_parse_error>Invalid document structure
</xml_parse_error>
(2 rows affected)