Example: importing XML documents or XML query results to an Adaptive Server table  Example: 'xmlerror' option capabilities with External File Access

Appendix C: XML Services and External File System Access

Example: storing parsed XML documents in the file system

You can parse the XML documents stored in the external file system and store the parsed result either in an Adaptive Server table or in the File Access system.

insert xmlxfsTab(filename , content)
select 'parsed'+t.filename,xmlparse(t.content) from xmlxfsTab t
-----------
(2 rows affected)

The following code sample queries the parsed documents stored in the XFS file system.

select filename , xmlextract("//book/title" , content)
from xmlxfsTab
where filename like 'parsed%'and filetype = 'REG'
filename
--------------------------------------------
parsedbookstore.1.xml   
<title>Seven Years in Trenton</title>
parsedbookstore.2.xml   
<title>Modern Database Management</title>

(2 rows affected)

The following code sample uses the xmlrepresentation built-in function to query only the File Access documents that are parsed XML (rather than other sorts of external files):

select filename , xmlextract("//book/title" , content)
from xmlxfsTab
where xmlrepresentation(content) = 0
filename
---------------------------------------
parsedbookstore.1.xml
<title>Seven Years in Trenton</title>       
parsedbookstore.2.xml     
<title>Modern Database Management</title>

(2 rows affected)




Copyright © 2005. Sybase Inc. All rights reserved. Example: 'xmlerror' option capabilities with External File Access

View this book as PDF