Santosh Kumar
Santosh Kumar

Reputation: 189

insert database(DB2) tuples as XML elements in XML file using java?

how to insert database(DB2) tuples as XML elements in XML file using java? Is there any possibility to retrieve XML elements which were entered earlier as database tuples?? or can they be used to provide a view customized to different users.

Upvotes: 1

Views: 618

Answers (1)

Fred Sobotka
Fred Sobotka

Reputation: 5332

Although it would help to see a bit of an example of what you're trying to accomplish, I am fairly certain that a couple of different XML features in DB2 (referred to collectively as pureXML) can help your application convert smoothly between XML documents and relational data.

Publishing tuples/rows as XML is done with SQL/XML functions such as XMLELEMENT, XMLATTRIBUTE, XMLFOREST, XMLAGG, and XMLSERIALIZE, to name a few. These functions have been available since DB2 V8.1, when they were introduced as part of the SQL:2003 spec. Other DBMS vendors support these functions in their products, too. To produce more sophisticated XML constructs, such as hierarchical data relationships and repeating elements, you will probably want to exploit common table expressions that use XMLAGG or XMLGROUP.

XML data can be stored natively in DB2 v9.1 and newer by using the XML datatype, which produces a column that accepts any well-formed XML input. If you instead want to decompose/shred the inbound XML into one or more columns of a relational table, the XMLTABLE function takes in an XML document and your XPath expressions to convert the relevant nodes into a traditional result set that can be referenced by a SQL insert statement.

Upvotes: 1

Related Questions