I have DB2 10 version. I need to extract the data from the XML and store it into a DB2 tables and i need to do it via stored procedure. When i searched for the documents i was not able to find a relevent doc where i can clearly understand the DB2 parser.
1) Is there a DB2 function available which automatically parse the XML and give me the tags and contents?
2) If so where will be the tags and contents are stored?
3) If not do i have to write the logic in stored procedure to parse and get the tags and variables?
Would be helpful if you could give me the concept and examples.
Pinned topic Parsing XML data in Mainframe DB2 via DB2 parser
Answered question This question has been answered.
Unanswered question This question has not been answered yet.
Updated on 2012-12-13T21:09:13Z at 2012-12-13T21:09:13Z by MatthiasNicola
MatthiasNicola 120000E28R322 Posts
Re: Parsing XML data in Mainframe DB2 via DB2 parser2012-12-13T21:09:13ZThis is the accepted answer. This is the accepted answer.Hi,
when you store XML in a DB2 table, DB2 will automatically invoke an XML parser as needed. You don't need to deal with the parsing explicitly.
To store XML documents in a DB2 table you can define a column of data type XML. That table can also have other columns. You can use the DB2 LOAD utility or regular insert statements to move XML (or a mix of XML and relational data) into the table. DB2 will automatically parse the XML for you and store each XML document as a tree (one document per row). You can then use SQL/XML (SQL + XPath) to query the data. Some examples for such queries are provided in this article:
If you don't want to store the XML documents in a column of type XML, you also have the option to shred the XML to a set of relational columns in one or multiple tables. Again, you can use SQL+XPath, i.e. the XMLTABLE function, to do this.
All of this can be done in stored procedures. So, you use SQL and/or XPath to work with the XML, and DB2 will parse the XML under the covers whenever needed.
For more comprehensive information and more examples, see: