Example: 'xmlerror' option capabilities with External File Access

An external (O/S) file system may contain a variety of data formats, and may contain both valid and invalid XML documents. You can use the xmlerror option of the xmlextract and xmltest functions to specify error actions for documents that are not valid XML.For example, a File Access directory structure may contain picture.jpg and nonxmldoc.txt files along with bookstore1.xml and bookstore.2.xml files:

select filename from xmlxfsTab
filename
-----------------------------------------
picture.jpg 
bookstore.1.xml 
bookstore.2.xml
nonxmldoc.txt

(4 rows affected)

The following code sample shows an XML query on both XML and non-XML data:

select filename, xmlextract("//book/title",content)
from xmlxfsTab
--------------
Msg 14702, Level 16, State 0:
Line 1:
XMLEXTRACT(): XML parser fatal error <<An exception occurred!
Type:TranscodingException,
Message:An invalid multi-byte source text sequence was
encountered>> at line 1, offset 1.