Loading ...
Sorry, an error occurred while loading the content.

Map problems

Expand Messages
  • lyoung@sundata.com.au
    I am a new user of XML-DBMS and am having problems with the map. I have a DTD:-
    Message 1 of 2 , Oct 4, 2000
    View Source
    • 0 Attachment
      I am a new user of XML-DBMS and am having problems with the map. I have a
      DTD:-

      <!ELEMENT xml (product+)>
      <!ELEMENT product (size+, prices)>
      <!ELEMENT size EMPTY>
      <!ELEMENT aud EMPTY>
      <!ELEMENT nzd EMPTY>
      <!ELEMENT prices (aud, nzd)>
      <!ATTLIST aud
      now NMTOKEN #REQUIRED
      was NMTOKEN #REQUIRED
      >
      <!ATTLIST nzd
      now NMTOKEN #REQUIRED
      >
      <!ATTLIST product
      sku NMTOKEN #REQUIRED
      >
      <!ATTLIST size
      code NMTOKEN #REQUIRED
      qty NMTOKEN #REQUIRED
      >

      and a copy of the XML I ultimately need to produce:-
      <?xml version="1.0" ?>
      <xml>
      <product sku="1110029">
      <size code="060" qty="15"/>
      <size code="070" qty="13"/>
      <price currency="AUD" now="7.50" was="8.50"/>
      <price currency="NZD" now="10.50"/>
      </product>
      <product sku="1130274">
      <size code="100" qty="15"/>
      <size code="105" qty="13"/>
      <size code="140" qty="23"/>
      <price currency="AUD" now="30.00" was="35.00"/>
      <price currency="NZD" now="45.00"/>
      </product>
      <product sku="3111010">
      <size code="-xs" qty="15"/>
      <size code="--s" qty="27"/>
      <price currency="AUD" now="3.50" was="4.50"/>
      <price currency="NZD" now="5.50"/>
      </product>
      </xml>

      All the data is on the one table, when I run GENERATE MAP it tries to
      create all sorts of tables. The table I'm using is called ITSOHF and some
      of the fields are
      sku = ITPRD
      size code = ITSZ1/ITSZ2/ITSZ3 etc
      qty = ITQTY1/ITQTY2/ITQTY3 etc.

      Is it possible to create a map for this?


      _____________________________
      Laura Young
      AS/400 Programmer
      Sundata
      Direct line 07 3004 7318


      VISIT OUR WEB SITE to see how we can help you achieve your business goals.
      http://www.sundata.com.au/

      SUNDATA PRODUCTS & SERVICES
      + E-Business Solutions
      + Application Development and Support
      + Local and Wide Area Networks
      + Mid-Range Servers
      + Business Continuity Service

      NOTICE - If you have received this message in error please notify Sundata
      immediately and destroy the original message. Thank you. Sundata has
      implemented anti-virus software, and whilst all care is taken, it is the
      recipient's responsibility to ensure that any attachments are scanned for
      viruses prior to use.

      [Non-text portions of this message have been removed]
    • Ronald Bourret
      The short answer is that it is not possible to create a map for this, but that it is possible to transfer the data and then transform the result to what you
      Message 2 of 2 , Oct 5, 2000
      View Source
      • 0 Attachment
        The short answer is that it is not possible to create a map for this,
        but that it is possible to transfer the data and then transform the
        result to what you want with the help of XSLT.

        The long answer:

        1) Your DTD does not match your XML. Therefore, I am going to assume
        that the XML is correct and that the correct DTD is:

        <!ELEMENT xml (product+)>
        <!ELEMENT product (size+, price+)>
        <!ATTLIST product
        sku NMTOKEN #REQUIRED>
        <!ELEMENT size EMPTY>
        <!ATTLIST size
        code NMTOKEN #REQUIRED
        qty NMTOKEN #REQUIRED>
        <!ELEMENT price EMPTY>
        <!ATTLIST price
        currency (AUD | NZD) #REQUIRED
        now CDATA #REQUIRED
        was CDATA #IMPLIED>

        It appears that the "was" attribute is used only when currency is AUD.
        Note that there is no way to express this in a DTD. (It might be
        possible in XML Schemas, but I'm not sure about that.)

        2) Because you are using a single table but have multiple code and
        quantity columns, there must be a limit to how many there are of each
        column. For example, you might have 10 of each. The same is true with
        the was/now values of currencies. Furthermore, because there is only a
        now attribute for NZD, I'm further assuming that you have columns like
        AUDWAS1, AUDNOW1, and NZDNOW1 instead of CURR1, WAS1, and NOW1. Thus,
        your table might look something like:

        ITSOHF
        ------
        ITPRD
        ITSZ1
        ...
        ITSZ10
        ITQTY1
        ...
        ITQTY10
        AUDWAS1
        ...
        AUDWAS10
        AUDNOW1
        ...
        AUDWAS10
        NZDWAS1
        ...
        NZDWAS10

        3) XML-DBMS assumes that hierarchy in the database matches hierarchy in
        the XML document. That is, when XML-DBMS generates a table structure
        from your DTD, it will generate a separate table for any element that
        has "children", either in the form of attributes or child elements. (In
        the reverse direction, it assumes an element for each table, with
        columns mapped to attributes or child elements.)

        The reason for this is that each element with "children" maps to a
        separate class, which then maps to a separate table. That is, the
        structure of the XML document matches the structure in the database.
        This is very easy to see visually in the case of child elements. (You
        can use your imagination with attributes.)

        <A> class A { table A
        <B>...</B> String B; column B
        <C>...</C> String C; column C
        <D>...</D> String D; column D
        </A> }

        For example, using the above DTD, XML-DBMS will generate separate tables
        for the product, size, and price elements. (In the case of the DTD
        listed below, it would generate separate tables for the product, size,
        prices, aud, and nzd elements.)

        In your case, you have introduced structure in the XML document that
        does not exist in the database. That is, you have grouped columns ITSZ1
        and ITQTY1 together into attributes of the same size element. Although
        you knew that these two columns deserved to be together, there is no way
        for XML-DBMS to predict this.

        Adding/eliminating structure that exists in XML and not in the database
        is something that I have looked into, but did not implement due to
        technical problems (impossibilities?). (For a rough explanation, see the
        file PassThrough.txt in the directory in which you installed XML-DBMS.)
        The only solution here is to use XSL Transformations (XSLT) to modify
        the XML generated by XML-DBMS.

        For example, I'll assume that you won't change your table. Thus,
        XML-DBMS will generate XML that looks something like the following,
        based on the table structure above. You can then use XSLT to match the
        various xxx1, xxx2, etc. elements and place these together as attributes
        of a size or price element.

        <xml>
        <product sku="...">
        <code1>...</code1>
        ...
        <code10>...</code10>
        <qty1>...</qty1>
        ...
        <qty10>...</qty10>
        <audwas1>...</audwas1>
        ...
        <audwas10>...</audwas10>
        <audnow1>...</audnow1>
        ...
        <audnow10>...</audnow10>
        <nzdnow1>...</nzdnow1>
        ...
        <nzdnow10>...</nzdnow10>
        </product>
        ...
        </xml>

        The map for this will be pretty straight-forward -- you need an
        IgnoreRoot for the xml element (with product as a PseudoRoot), a
        ClassMap for product, and child PropertyMaps for each of the remaining
        elements.

        4) One other thing that is interesting to note here is that the table
        contains multiple columns storing the same type of value (multiple
        quantities, multiple currency values, etc.) In a completely normalized
        database, these would be stored in separate tables. For example,
        assuming the structure introduced in the XML, the tables would be:

        product
        sku

        size
        sku
        code
        qty

        price
        sku
        currency
        was
        now

        Grouping multiple values into a non-normal table is a reasonable thing
        to do -- at the cost of some null values (when there are less values
        than columns) you save joins, which are expensive. The obvious drawback
        to this is that the number of possible values is limited to the number
        of columns.

        In XML-DBMS 1.0, I looked into supporting this, but cut it due to lack
        of time and because DTDs can't easily limit the number of child elements
        (each child must be enumerated separately). What is interesting about
        this is that XML Schemas do support a limited number of child elements
        -- that is, you can say that element A has exactly (or no more than)
        three B elements as children. When the number of children is limited, it
        is then quite reasonable to store them in the parent table. Therefore,
        I've added this mapping feature to the version 3.0 and beyond spec.

        Anyway, I hope this helps answer your question. Write back if you're
        still confused -- there's a lot of info here.

        -- Ron

        lyoung@... wrote:
        >
        > I am a new user of XML-DBMS and am having problems with the map. I have a
        > DTD:-
        >
        > <!ELEMENT xml (product+)>
        > <!ELEMENT product (size+, prices)>
        > <!ELEMENT size EMPTY>
        > <!ELEMENT aud EMPTY>
        > <!ELEMENT nzd EMPTY>
        > <!ELEMENT prices (aud, nzd)>
        > <!ATTLIST aud
        > now NMTOKEN #REQUIRED
        > was NMTOKEN #REQUIRED
        > >
        > <!ATTLIST nzd
        > now NMTOKEN #REQUIRED
        > >
        > <!ATTLIST product
        > sku NMTOKEN #REQUIRED
        > >
        > <!ATTLIST size
        > code NMTOKEN #REQUIRED
        > qty NMTOKEN #REQUIRED
        > >
        >
        > and a copy of the XML I ultimately need to produce:-
        > <?xml version="1.0" ?>
        > <xml>
        > <product sku="1110029">
        > <size code="060" qty="15"/>
        > <size code="070" qty="13"/>
        > <price currency="AUD" now="7.50" was="8.50"/>
        > <price currency="NZD" now="10.50"/>
        > </product>
        > <product sku="1130274">
        > <size code="100" qty="15"/>
        > <size code="105" qty="13"/>
        > <size code="140" qty="23"/>
        > <price currency="AUD" now="30.00" was="35.00"/>
        > <price currency="NZD" now="45.00"/>
        > </product>
        > <product sku="3111010">
        > <size code="-xs" qty="15"/>
        > <size code="--s" qty="27"/>
        > <price currency="AUD" now="3.50" was="4.50"/>
        > <price currency="NZD" now="5.50"/>
        > </product>
        > </xml>
        >
        > All the data is on the one table, when I run GENERATE MAP it tries to
        > create all sorts of tables. The table I'm using is called ITSOHF and some
        > of the fields are
        > sku = ITPRD
        > size code = ITSZ1/ITSZ2/ITSZ3 etc
        > qty = ITQTY1/ITQTY2/ITQTY3 etc.
        >
        > Is it possible to create a map for this?

        --
        Ronald Bourret
        Programming, Writing, and Training
        XML, Databases, and Schemas
        http://www.rpbourret.com
      Your message has been successfully submitted and would be delivered to recipients shortly.