XML Shredding Based on a Stylesheet | XML Data Type | Teradata Vantage - XML Shredding Based on a Stylesheet - Advanced SQL Engine - Teradata Database

XML Data Type

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-22
dita:mapPath
amr1556233250442.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1140
lifecycle
previous
Product Category
Teradata Vantageā„¢

XML shredding is the process of extracting values from XML documents to populate tables in the database. One way to define the mapping from the XML document's tree structure to the database's tabular structure is to use an annotated schema. An alternative is to use an XSLT stylesheet-based mapping.

For efficient memory use, streamed shredding does not load the entire document into memory. XSLT-based shredding loads the document in memory, giving it more flexibility than one-pass processing over the document.

XSLT-based shredding is accomplished using shredding stored procedures:
  • XSLT_SHRED - used for single XML document shredding
  • XSLT_SHRED_BATCH - used to shred multiple XML documents

Perform these typical tasks to shred XML documents.

  1. Load the XML document to be shredded into an XML column of a staging table.
    The XML document must conform to W3C XML standards. The following is an example of such an XML document.
    <<?xml version="1.0"?>
    <Root>
     <predictixOfferMessage>
      <offer>
       <offerId>1000002</offerId>
      </offer>
      <mediaBlock>
       <mediaBlockId>90000000010002</mediaBlockId>
      </mediaBlock>
     </predictixOfferMessage>
    </Root>
    
  2. Define an SQL query that returns a result set with two columns:
    • An ID column
    • The XML column that contains the XML document to be shredded
  3. Create an XSLT stylesheet that defines how the XML document is shred to the target tables.
  4. Store the XSLT stylesheet so that it can be easily referenced; for example, store it in a stylesheet repository table.
  5. Call the XSLT_SHRED_BATCH stored procedure with the following arguments:
    • The SQL query you defined in step 2
    • The XSLT stylesheet you saved in step 4
    The XML documents returned by the SQL query are shredded based on the mapping in the XSLT stylesheet. This results in the target tables being populated with data from these documents. NULL is inserted into target columns in some cases (for example, where the corresponding elements in the XML are empty or missing). NULL is stored if the given element path is missing in the input XML document.