Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2003
    Posts
    47

    Unanswered: DB2 xml extender

    Hi All,

    I have a requirement to parse the xml and store specific elements into a table.

    I found the following example on IBM.

    XML:
    <?xml version="1.0"?>
    <!DOCTYPE Order SYSTEM "dxx_install/samples/db2xml/dtd/getstart.dtd">
    <Order key="1">
    <Customer>
    <Name>American Motors</Name>
    <Email>parts@am.com</Email>
    </Customer>
    <Part color="black ">
    <key>68</key>
    <Quantity>36</Quantity>
    <ExtendedPrice>34850.16</ExtendedPrice>
    <Tax>6.000000e-02</Tax>
    <Shipment>
    <ShipDate>1998-08-19</ShipDate>
    <ShipMode>BOAT </ShipMode>
    </Shipment>
    <Shipment>
    <ShipDate>1998-08-19</ShipDate>
    <ShipMode>AIR </ShipMode>
    </Shipment>
    </Part>
    <Part color="red ">
    <key>128</key>
    <Quantity>28</Quantity>
    <ExtendedPrice>38000.00</ExtendedPrice>
    <Tax>7.000000e-02</Tax>
    <Shipment>
    <ShipDate>1998-12-30</ShipDate>
    <ShipMode>TRUCK </ShipMode>
    </Shipment>
    </Part>
    </Order>




    CREATE TABLE t1(name varchar(30));
    INSERT INTO t1 values (
    DB2XML.extractVarchar(DB2XML.xmlfile('dxx_install
    /samples/extenders/db2xml/xml/getstart.xml'),
    '/Order/Customer/Name'));
    SELECT * from t1;
    Table function example:

    In the following example, the value of Color is extracted as VARCHAR. The examples assume that you are using the DB2 command shell, in which you do not need to type "DB2" at the beginning of each command.

    SELECT*
    FROM TABLE(
    DB2XML.extractVarchars(DB2XML.XMLFile('dxx_install
    /samples/xml/getstart.xml'),
    '/Order/Part/@color')) AS X;


    Here are my list of questions.


    1. Because DB2XML.XMLFile reads the file from physical location, does the size of the file matters.

    2. I want to extract more than one parameter for example key and quantity,
    How can I specify both elements?



    Thanks in advance.
    Shri
    Last edited by palchuri; 10-29-07 at 22:04.
    p.srinivasarao

  2. #2
    Join Date
    May 2003
    Posts
    113
    For your 2nd question:
    "2. I want to extract more than one parameter for example key and quantity,
    How can I specify both elements?"

    If you are on V9, use XMLTABLE() instead of xml extender.

    XMLTABLE is 'invented' partially because of the scenario you are facing

  3. #3
    Join Date
    Jan 2003
    Posts
    47

    db2 version

    Db2 Version Is 8.1
    p.srinivasarao

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •