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

FAQ: How to use the InlineMap element of the v2.0 mapping language

Expand Messages
  • Ronald Bourret
    It is common to group related elements in XML with another element. It is also common that this wrapper element does not directly correspond to any structure
    Message 1 of 3 , Mar 9 10:50 PM
    • 0 Attachment
      It is common to group related elements in XML with another element. It
      is also common that this "wrapper" element does not directly correspond
      to any structure in the database. For example, consider the following:

      <Customer>
      <Number>123</Number>
      <Name>Gallagher Industries</Name>
      <Address>
      <Street>123 Main St.</Street>
      <City>Chicago</City>
      <State>IL</State>
      <Country>US</Country>
      <PostCode>60609</PostCode>
      </Address>
      </Customer>

      In this example, the Address element is used to group the address
      elements. However, it is unlikely to correspond to any structure in the
      database. That is, the address information is likely to be stored in the
      customer table, not in a separate address table.

      The InlineMap element allows you to map the attributes, child elements,
      and PCDATA of a wrapper element as if they belonged to the parent of the
      wrapper element. For example, Street, City, State, Country, and PostCode
      can be mapped as if they were children of the Customer element, not the
      Address element. The main advantage of this is that it saves having to
      use XSLT to eliminate the Address element (on incoming documents) or add
      the Address element (on outgoing documents).

      The InlineMap element type is similar to the ClassMap element type in
      that it has PropertyMap, InlineMap, and RelatedClass children. The
      PropertyMap children are used to map the attributes, child elements, and
      PCDATA of the wrapper element. The InlineMap children are used to map
      wrapper elements that are children of the wrapper element being wrapped.
      (Note that wrapper elements can be nested arbitrarily deep.) The
      RelatedClass children are used to map any children of the wrapper
      element that are mapped using ClassMaps.

      For example, the ClassMap element used to map the Customer element type
      might be as follows. Notice that the PropertyMaps for Street, City,
      State, and so on are nested inside the InlineMap for Address. Notice
      also that the STREET column referred to in the PropertyMap for the
      Street element is in the CUSTOMERS table.

      <ClassMap>
      <ElementType Name="Customer" />
      <ToClassTable Name="CUSTOMERS" />

      ... PropertyMap elements for Number and Name ...

      <InlineMap>
      <ElementType Name="Address" />

      <PropertyMap>
      <ElementType Name="Street" />
      <ToColumn Name="STREET" />
      </PropertyMap>

      ... PropertyMap elements for City, State, Country, and
      PostCode ...

      </InlineMap>
      </ClassMap>

      InlineMap elements can also have an optional OrderColumn or FixedOrder
      child. This is used to order the wrapper element among its siblings when
      constructing XML documents. For example, to ensure that the Number,
      Name, and Address children of Customer appear in that order, you can use
      the following FixedOrder elements:

      <ClassMap>
      <ElementType Name="Customer" />
      <ToClassTable Name="CUSTOMERS" />
      <PropertyMap>
      <ElementType Name="Number" />
      <ToColumn Name="NUMBER" />
      <FixedOrder Value="1" /> <!-- FixedOrder -->
      </PropertyMap>
      <PropertyMap>
      <ElementType Name="Name" />
      <ToColumn Name="NAME" />
      <FixedOrder Value="2" /> <!-- FixedOrder -->
      </PropertyMap>
      <InlineMap>
      <ElementType Name="Address" />
      <FixedOrder Value="3" /> <!-- FixedOrder -->

      ... PropertyMap elements for Street, City, State, Country,
      and PostCode ...

      </InlineMap>
      </ClassMap>

      Note also that FixedOrder and OrderColumn elements in PropertyMap,
      InlineMap, and RelatedClass elements in an InlineMap refer to the order
      of the mapped element in the wrapper element, not the class element. For
      example, a FixedOrder element inside the PropertyMap for Street refers
      to the order of the Street element in Address, not Customer.

      InlineMap elements have one restriction. Only a single child of a given
      type can be inlined. For example, in the following document, B can be
      inlined by D cannot. This is necessary for reconstructing the inlined
      element.

      <A>
      <!-- B occurs once inside A and can be inlined. -->
      <B>
      <C>...</C>
      </B>
      <!-- D occurs more than once inside A and cannot be inlined.
      -->
      <D>
      <E>...</E>
      </D>
      <D>
      <E>...</E>
      </D>
      <F>...</F>
      </A>
    • Wood, Cindy
      I am new to xmldbms and having a problem when I try to apply the InLineMap capabilities as listed below. I receive the following error: Error:
      Message 2 of 3 , May 27, 2004
      • 0 Attachment
        I am new to xmldbms and having a problem when I try to apply the
        InLineMap capabilities as listed below. I receive the following error:

        Error: java.lang.NullPointerException
        java.lang.NullPointerException
        at
        org.xmlmiddleware.xmldbms.DOMToDBMS.setPropertyColumn(DOMToDBMS.java:109
        0)
        at
        org.xmlmiddleware.xmldbms.DOMToDBMS.processProperty(DOMToDBMS.java:807)
        at
        org.xmlmiddleware.xmldbms.DOMToDBMS.processChild(DOMToDBMS.java:685)
        at
        org.xmlmiddleware.xmldbms.DOMToDBMS.processChildren(DOMToDBMS.java:630)
        at
        org.xmlmiddleware.xmldbms.DOMToDBMS.processChild(DOMToDBMS.java:707)
        at
        org.xmlmiddleware.xmldbms.DOMToDBMS.processChildren(DOMToDBMS.java:630)
        at
        org.xmlmiddleware.xmldbms.DOMToDBMS.processClassRow(DOMToDBMS.java:544)
        at
        org.xmlmiddleware.xmldbms.DOMToDBMS.processRoot(DOMToDBMS.java:447)
        at
        org.xmlmiddleware.xmldbms.DOMToDBMS.processRoot(DOMToDBMS.java:477)
        at
        org.xmlmiddleware.xmldbms.DOMToDBMS.processRoot(DOMToDBMS.java:477)
        at
        org.xmlmiddleware.xmldbms.DOMToDBMS.storeDocument(DOMToDBMS.java:368)
        at
        org.xmlmiddleware.xmldbms.DOMToDBMS.storeDocument(DOMToDBMS.java:317)
        at
        org.xmlmiddleware.xmldbms.tools.Transfer.storeDocumentInternal(Transfer.
        java:840)
        at
        org.xmlmiddleware.xmldbms.tools.Transfer.storeDocument(Transfer.java:525
        )

        I walked through the code and found that when it gets into the
        setPorpertyColumn, the formatter for the EXTR_SYS_ID column is null. Is
        there something I need to do to get the formatter set correctly or am I
        doing something wrong?

        I have included the .map file and .xml file that I am using. The fields
        in question are in blue in the map file. Look for NamedInured and
        you'll find them.

        Below is the snippet from the variables at the point when
        setPropertyColumn is executed and fails.

        propMap= PropertyMap (id=118)
        column= Column (id=120)
        formatter= null
        length= -1
        lengthExists= false
        name= "EXTR_SYS_ID"
        nullability= 0
        precision= -1
        precisionExists= false
        resultSetIndex= 3
        scale= -2147483648
        scaleExists= false
        type= 0
        containsXML= false
        isTokenList= false
        linkInfo= null
        orderInfo= null
        table= null
        tokenListOrderInfo= null
        type= 1
        xmlName= XMLName (id=121)

        Any help would be greatly appreciated.

        Thanks,

        Cindy Wood
        Senior Software Engineer
        SDN 843
        Ext 54353
        Phone (603)245-4353



        -----Original Message-----
        From: Ronald Bourret [mailto:rpbourret@...]
        Sent: Wednesday, March 10, 2004 1:51 AM
        To: xml-dbms@yahoogroups.com
        Subject: [xml-dbms] FAQ: How to use the InlineMap element of the v2.0
        mapping language


        It is common to group related elements in XML with another element. It
        is also common that this "wrapper" element does not directly correspond
        to any structure in the database. For example, consider the following:

        <Customer>
        <Number>123</Number>
        <Name>Gallagher Industries</Name>
        <Address>
        <Street>123 Main St.</Street>
        <City>Chicago</City>
        <State>IL</State>
        <Country>US</Country>
        <PostCode>60609</PostCode>
        </Address>
        </Customer>

        In this example, the Address element is used to group the address
        elements. However, it is unlikely to correspond to any structure in the
        database. That is, the address information is likely to be stored in the
        customer table, not in a separate address table.

        The InlineMap element allows you to map the attributes, child elements,
        and PCDATA of a wrapper element as if they belonged to the parent of the
        wrapper element. For example, Street, City, State, Country, and PostCode
        can be mapped as if they were children of the Customer element, not the
        Address element. The main advantage of this is that it saves having to
        use XSLT to eliminate the Address element (on incoming documents) or add
        the Address element (on outgoing documents).

        The InlineMap element type is similar to the ClassMap element type in
        that it has PropertyMap, InlineMap, and RelatedClass children. The
        PropertyMap children are used to map the attributes, child elements, and
        PCDATA of the wrapper element. The InlineMap children are used to map
        wrapper elements that are children of the wrapper element being wrapped.
        (Note that wrapper elements can be nested arbitrarily deep.) The
        RelatedClass children are used to map any children of the wrapper
        element that are mapped using ClassMaps.

        For example, the ClassMap element used to map the Customer element type
        might be as follows. Notice that the PropertyMaps for Street, City,
        State, and so on are nested inside the InlineMap for Address. Notice
        also that the STREET column referred to in the PropertyMap for the
        Street element is in the CUSTOMERS table.

        <ClassMap>
        <ElementType Name="Customer" />
        <ToClassTable Name="CUSTOMERS" />

        ... PropertyMap elements for Number and Name ...

        <InlineMap>
        <ElementType Name="Address" />

        <PropertyMap>
        <ElementType Name="Street" />
        <ToColumn Name="STREET" />
        </PropertyMap>

        ... PropertyMap elements for City, State, Country, and
        PostCode ...

        </InlineMap>
        </ClassMap>

        InlineMap elements can also have an optional OrderColumn or FixedOrder
        child. This is used to order the wrapper element among its siblings when
        constructing XML documents. For example, to ensure that the Number,
        Name, and Address children of Customer appear in that order, you can use
        the following FixedOrder elements:

        <ClassMap>
        <ElementType Name="Customer" />
        <ToClassTable Name="CUSTOMERS" />
        <PropertyMap>
        <ElementType Name="Number" />
        <ToColumn Name="NUMBER" />
        <FixedOrder Value="1" /> <!-- FixedOrder -->
        </PropertyMap>
        <PropertyMap>
        <ElementType Name="Name" />
        <ToColumn Name="NAME" />
        <FixedOrder Value="2" /> <!-- FixedOrder -->
        </PropertyMap>
        <InlineMap>
        <ElementType Name="Address" />
        <FixedOrder Value="3" /> <!-- FixedOrder -->

        ... PropertyMap elements for Street, City, State, Country,
        and PostCode ...

        </InlineMap>
        </ClassMap>

        Note also that FixedOrder and OrderColumn elements in PropertyMap,
        InlineMap, and RelatedClass elements in an InlineMap refer to the order
        of the mapped element in the wrapper element, not the class element. For
        example, a FixedOrder element inside the PropertyMap for Street refers
        to the order of the Street element in Address, not Customer.

        InlineMap elements have one restriction. Only a single child of a given
        type can be inlined. For example, in the following document, B can be
        inlined by D cannot. This is necessary for reconstructing the inlined
        element.

        <A>
        <!-- B occurs once inside A and can be inlined. -->
        <B>
        <C>...</C>
        </B>
        <!-- D occurs more than once inside A and cannot be inlined.
        -->
        <D>
        <E>...</E>
        </D>
        <D>
        <E>...</E>
        </D>
        <F>...</F>
        </A>



        To post a message, send it to: xml-dbms@yahoogroups.com
        To unsubscribe, send a blank message to:
        xml-dbms-unsubscribe@yahoogroups.com
        Or join the newsgroup at: news://news.barkto.com/homeless.xml.xml-dbms
        Yahoo! Groups Links







        [Non-text portions of this message have been removed]
      • Ronald Bourret
        I m sorry about the very late answer. The NullPointerException seems to have been caused by problems in your map document, which is invalid. You should always
        Message 3 of 3 , Jul 5, 2004
        • 0 Attachment
          I'm sorry about the very late answer.

          The NullPointerException seems to have been caused by problems in your
          map document, which is invalid. You should always validate your map,
          action, and filter documents before using them, as XML-DBMS has
          unpredictable results when used with invalid map, action, and filter
          documents.

          Here is a list of problems:

          1) In your ClassMap element, you intermix PropertyMap and InlineMap
          children. All PropertyMap children must appear before any InlineMap
          children, which must appear before any RelatedClass children. For more
          information, see the content model for ClassMap in xmldbms2.dtd.

          2) In some Column elements, you use attributes named Datatype. This
          should be DataType.

          3) The Databases element must contain a Database element, which then
          contains the Catalog element.

          I also found a couple of other problems:

          1) You specify a pattern of "yyy.dd.MM" in your SimpleDateFormat. Do you
          mean "yyyy.dd.MM"? In either case, this doesn't match the data in your
          instance document, which uses the format "yyyy-dd-MM" (or "yyyy-MM-dd").

          2) Your RelatedClass elements will not work in the way you expect them
          to. In particular, RelatedClass elements can only be used when one
          complex element is nested inside another complex element. In your case,
          this means that NamedInsured should be nested inside IAMHeader.
          Currently, your instance document has NamedInsured as (essentially) a
          sibling of IAMHeader. Furthermore, the RelatedClass element must be
          inside the ClassMap of the parent element type. In your case, this means
          that the RelatedClass element should be in the ClassMap for IAMHeader.

          To fix this, you need to do the following:

          a) Use XSLT to convert your incoming documents so that
          InsuredOrPrincipal is nested beneath IAMHeader.

          b) Add a RelatedClass element for InsuredOrPrincipal to the ClassMap for
          IAMHeader.

          c) Remove the RelatedClass element from the ClassMap for
          InsuredOrPrincipal.

          d) Instead of mapping NamedInsured with a ClassMap, map
          InsuredOrPrincipal. This class map will be the same as the class map for
          NamedInsured except that (i) it maps InsuredOrPrincipal and (b) it wraps
          all of the PropertyMaps and InlineMaps inside yet another InlineMap,
          which maps NamedInsured.

          An alternate solution is to use XSLT to add TransactionId and MessageId
          children to NamedInsured. (These would be copied from the IAMHeader
          element.) You could then remove the RelatedClass child of the ClassMap
          for NamedInsured.

          Finally, in tracking all of this down, I discovered a bug in
          org.xmlmiddleware.xmldbms.datahandlers.DataHandlerBase. In particular,
          when a table does not contain a primary key, the getRefreshCols method
          returns a NullPointerException. To fix this, modify the code in
          getRefreshCols to check if the primary key is null:

          protected Column[] getRefreshCols(Table table)
          {
          if(m_refreshCols.contains(table))
          return (Column[])m_refreshCols.get(table);

          Vector colVec = new Vector();

          // Add the primary key
          Key priKey = table.getPrimaryKey();
          // Add this line:
          if (priKey != null) {
          if(priKey.getKeyGeneration() == Key.DATABASE)
          {
          Column[] priCols = priKey.getColumns();
          for(int i = 0; i < priCols.length; i++)
          colVec.addElement(priCols[i]);
          }
          // Add this line:
          }

          ...
          }

          -- Ron

          "Wood, Cindy" wrote:
          >
          > I am new to xmldbms and having a problem when I try to apply the
          > InLineMap capabilities as listed below. I receive the following error:
          >
          > Error: java.lang.NullPointerException
          > java.lang.NullPointerException
          > at
          > org.xmlmiddleware.xmldbms.DOMToDBMS.setPropertyColumn(DOMToDBMS.java:109
          > 0)
          > at
          > org.xmlmiddleware.xmldbms.DOMToDBMS.processProperty(DOMToDBMS.java:807)
          > at
          > org.xmlmiddleware.xmldbms.DOMToDBMS.processChild(DOMToDBMS.java:685)
          > at
          > org.xmlmiddleware.xmldbms.DOMToDBMS.processChildren(DOMToDBMS.java:630)
          > at
          > org.xmlmiddleware.xmldbms.DOMToDBMS.processChild(DOMToDBMS.java:707)
          > at
          > org.xmlmiddleware.xmldbms.DOMToDBMS.processChildren(DOMToDBMS.java:630)
          > at
          > org.xmlmiddleware.xmldbms.DOMToDBMS.processClassRow(DOMToDBMS.java:544)
          > at
          > org.xmlmiddleware.xmldbms.DOMToDBMS.processRoot(DOMToDBMS.java:447)
          > at
          > org.xmlmiddleware.xmldbms.DOMToDBMS.processRoot(DOMToDBMS.java:477)
          > at
          > org.xmlmiddleware.xmldbms.DOMToDBMS.processRoot(DOMToDBMS.java:477)
          > at
          > org.xmlmiddleware.xmldbms.DOMToDBMS.storeDocument(DOMToDBMS.java:368)
          > at
          > org.xmlmiddleware.xmldbms.DOMToDBMS.storeDocument(DOMToDBMS.java:317)
          > at
          > org.xmlmiddleware.xmldbms.tools.Transfer.storeDocumentInternal(Transfer.
          > java:840)
          > at
          > org.xmlmiddleware.xmldbms.tools.Transfer.storeDocument(Transfer.java:525
          > )
          >
          > I walked through the code and found that when it gets into the
          > setPorpertyColumn, the formatter for the EXTR_SYS_ID column is null. Is
          > there something I need to do to get the formatter set correctly or am I
          > doing something wrong?
          >
          > I have included the .map file and .xml file that I am using. The fields
          > in question are in blue in the map file. Look for NamedInured and
          > you'll find them.
          >
          > Below is the snippet from the variables at the point when
          > setPropertyColumn is executed and fails.
          >
          > propMap= PropertyMap (id=118)
          > column= Column (id=120)
          > formatter= null
          > length= -1
          > lengthExists= false
          > name= "EXTR_SYS_ID"
          > nullability= 0
          > precision= -1
          > precisionExists= false
          > resultSetIndex= 3
          > scale= -2147483648
          > scaleExists= false
          > type= 0
          > containsXML= false
          > isTokenList= false
          > linkInfo= null
          > orderInfo= null
          > table= null
          > tokenListOrderInfo= null
          > type= 1
          > xmlName= XMLName (id=121)
          >
          > Any help would be greatly appreciated.
          >
          > Thanks,
          >
          > Cindy Wood
          > Senior Software Engineer
          > SDN 843
          > Ext 54353
          > Phone (603)245-4353
          >
          > -----Original Message-----
          > From: Ronald Bourret [mailto:rpbourret@...]
          > Sent: Wednesday, March 10, 2004 1:51 AM
          > To: xml-dbms@yahoogroups.com
          > Subject: [xml-dbms] FAQ: How to use the InlineMap element of the v2.0
          > mapping language
          >
          > It is common to group related elements in XML with another element. It
          > is also common that this "wrapper" element does not directly correspond
          > to any structure in the database. For example, consider the following:
          >
          > <Customer>
          > <Number>123</Number>
          > <Name>Gallagher Industries</Name>
          > <Address>
          > <Street>123 Main St.</Street>
          > <City>Chicago</City>
          > <State>IL</State>
          > <Country>US</Country>
          > <PostCode>60609</PostCode>
          > </Address>
          > </Customer>
          >
          > In this example, the Address element is used to group the address
          > elements. However, it is unlikely to correspond to any structure in the
          > database. That is, the address information is likely to be stored in the
          > customer table, not in a separate address table.
          >
          > The InlineMap element allows you to map the attributes, child elements,
          > and PCDATA of a wrapper element as if they belonged to the parent of the
          > wrapper element. For example, Street, City, State, Country, and PostCode
          > can be mapped as if they were children of the Customer element, not the
          > Address element. The main advantage of this is that it saves having to
          > use XSLT to eliminate the Address element (on incoming documents) or add
          > the Address element (on outgoing documents).
          >
          > The InlineMap element type is similar to the ClassMap element type in
          > that it has PropertyMap, InlineMap, and RelatedClass children. The
          > PropertyMap children are used to map the attributes, child elements, and
          > PCDATA of the wrapper element. The InlineMap children are used to map
          > wrapper elements that are children of the wrapper element being wrapped.
          > (Note that wrapper elements can be nested arbitrarily deep.) The
          > RelatedClass children are used to map any children of the wrapper
          > element that are mapped using ClassMaps.
          >
          > For example, the ClassMap element used to map the Customer element type
          > might be as follows. Notice that the PropertyMaps for Street, City,
          > State, and so on are nested inside the InlineMap for Address. Notice
          > also that the STREET column referred to in the PropertyMap for the
          > Street element is in the CUSTOMERS table.
          >
          > <ClassMap>
          > <ElementType Name="Customer" />
          > <ToClassTable Name="CUSTOMERS" />
          >
          > ... PropertyMap elements for Number and Name ...
          >
          > <InlineMap>
          > <ElementType Name="Address" />
          >
          > <PropertyMap>
          > <ElementType Name="Street" />
          > <ToColumn Name="STREET" />
          > </PropertyMap>
          >
          > ... PropertyMap elements for City, State, Country, and
          > PostCode ...
          >
          > </InlineMap>
          > </ClassMap>
          >
          > InlineMap elements can also have an optional OrderColumn or FixedOrder
          > child. This is used to order the wrapper element among its siblings when
          > constructing XML documents. For example, to ensure that the Number,
          > Name, and Address children of Customer appear in that order, you can use
          > the following FixedOrder elements:
          >
          > <ClassMap>
          > <ElementType Name="Customer" />
          > <ToClassTable Name="CUSTOMERS" />
          > <PropertyMap>
          > <ElementType Name="Number" />
          > <ToColumn Name="NUMBER" />
          > <FixedOrder Value="1" /> <!-- FixedOrder -->
          > </PropertyMap>
          > <PropertyMap>
          > <ElementType Name="Name" />
          > <ToColumn Name="NAME" />
          > <FixedOrder Value="2" /> <!-- FixedOrder -->
          > </PropertyMap>
          > <InlineMap>
          > <ElementType Name="Address" />
          > <FixedOrder Value="3" /> <!-- FixedOrder -->
          >
          > ... PropertyMap elements for Street, City, State, Country,
          > and PostCode ...
          >
          > </InlineMap>
          > </ClassMap>
          >
          > Note also that FixedOrder and OrderColumn elements in PropertyMap,
          > InlineMap, and RelatedClass elements in an InlineMap refer to the order
          > of the mapped element in the wrapper element, not the class element. For
          > example, a FixedOrder element inside the PropertyMap for Street refers
          > to the order of the Street element in Address, not Customer.
          >
          > InlineMap elements have one restriction. Only a single child of a given
          > type can be inlined. For example, in the following document, B can be
          > inlined by D cannot. This is necessary for reconstructing the inlined
          > element.
          >
          > <A>
          > <!-- B occurs once inside A and can be inlined. -->
          > <B>
          > <C>...</C>
          > </B>
          > <!-- D occurs more than once inside A and cannot be inlined.
          > -->
          > <D>
          > <E>...</E>
          > </D>
          > <D>
          > <E>...</E>
          > </D>
          > <F>...</F>
          > </A>
          >
          > To post a message, send it to: xml-dbms@yahoogroups.com
          > To unsubscribe, send a blank message to:
          > xml-dbms-unsubscribe@yahoogroups.com
          > Or join the newsgroup at: news://news.barkto.com/homeless.xml.xml-dbms
          > Yahoo! Groups Links
          >
          >
          >
          > [Non-text portions of this message have been removed]
          >
          >
          > To post a message, send it to: xml-dbms@yahoogroups.com
          > To unsubscribe, send a blank message to: xml-dbms-unsubscribe@yahoogroups.com
          > Yahoo! Groups Links
          >
          >
          >
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.