Download XML for DB2 Information Integration nformation

Transcript
Publishing relational data as XML
If you want to publish relational data as XML, the best choice is to use SQL/XML.
SQL/XML is extremely flexible and allows almost arbitrary XML documents to be
constructed. This saves you from having to use local (database-specific) and
global XML schemas — you can usually publish directly to the global XML
schema.
The second choice is to use the publishing capabilities of DB2 XML Extender.
There are two possibilities here: SQL statement mapping and RDB node
mapping. Of these two, SQL statement mapping is probably easier to use for
simple documents— you just construct the SELECT statement you want and
map it to an XML document. However, since SQL statement mapping DAD files
have a number of restrictions (see “SQL statement mapping DAD documents” on
page 29), it makes them less suited for more complex documents. RDB node
mapping may more difficult to get your arms around because XML Extender
constructs the SELECT statement(s) for you (based on the RDB nodes in your
DAD file). For example, you cannot use GROUP BY or ORDER BY clauses in
RDB node mapping.
On the other hand, you must use RDB node mapping if you also want to shred
XML documents that use the same XML schema. Regardless of which type of
mapping you use, you will often need to use XSLT to transform the resulting XML
document to one that uses your global XML schema.
The third choice is to write your own code. There are two choices here: writing
code that is specific to a particular XML schema and database schema, and
writing generic code that is driven by external information, such as a mapping
file. The first allows you to easily handle complex XML documents, but can be
expensive to maintain. The second is easy if you use the table-based mapping,
but that limits the XML documents you can handle. It is significantly harder if you
use more complex mappings, such as an object-relational mapping. Perhaps the
best compromise when you decide to write code yourself, is to write generic code
that uses the table-based mapping and use XSLT to transform between a local,
table-based XML schema and a global XML schema.
Shredding XML documents into relational tables
If you want to shred XML documents into relational tables, the best choice is to
use DB2 XML Extender with an RDB node mapping (there is no SQL based
mapping when shredding). You can also use the XML Wrapper to shred XML
documents. This requires you to insert the data for each table separately, but
does allow you to shred some documents that cannot be handled by the XML
Extender due to referential integrity constraints.
You can also write your own code to shred XML documents into relational tables.
As with writing your own code to publish relational data as XML, the best
compromise when writing all the code yourself, is to write generic code that uses
Chapter 2. XML services in DB2 and DB2 Information Integrator
53