ProDataSet and Hierarchical XML

Posted by alextrs on 02-Sep-2010 08:21

Hello Guys,

Is there any way how I can create hierarchical XML using ProDataSet(or any other simple way to do that)?

example:

<ProDataSet>

  <tHeader>
  <OrderNo>300000248</OrderNo>
  <Branch>1</Branch>      
      <lin_detail>
          <tLines>
          <OrderNo>300000248</OrderNo>
          <OrdLineNo>1</OrdLineNo>
               <misc_detail>
                   <tMisc>
                        <OrdLineNo>1</OrdLineNo>
                   </tMisc>
                   <tMisc>
                        <OrdLineNo>1</OrdLineNo>
                   </tMisc>
               </misc_detail>
          </tLines>
     </lin_detail>
  </tHeader>
</ProDataSet>

I was able to create such XML using "NESTED" option of ProDataSet:

<ProDataSet>

  <tHeader>
  <OrderNo>300000248</OrderNo>
  <Branch>HG1</Branch>      
     <tLines>
        <OrderNo>300000248</OrderNo>
        <OrdLineNo>1</OrdLineNo>
        <tMisc>
           <OrdLineNo>1</OrdLineNo>
        </tMisc>
        <tMisc>
           <OrdLineNo>1</OrdLineNo>
        </tMisc>
     </tLines>
  </tHeader>
</ProDataSet>

but the company who needs this XML, wants to have
   <lin_detail>  ROWSET Start
      <misc_detail> ROWSET Start

Thank you!

All Replies

Posted by Robin Brown on 02-Sep-2010 12:28

You can define temp-tables for lin_detail and misc_detail with a single field with XML-NODE-TYPE "HIDDEN", add this same hidden field to the other temp-tables, and define your NESTED data-relations on the hidden field.  The drawback of this approach is that READ-XML will not be able to re-create the relationships, since the relation-field is hidden.  You can also create the XML yourself using the SAX-WRITER or X-DOCUMENT objects.

Here is an example ProDataSet definition:

DEFINE TEMP-TABLE tHeader
    FIELD OrderNo AS INT
    FIELD Branch AS INT
    FIELD hidIDAS INT XML-NODE-TYPE "HIDDEN".

DEFINE TEMP-TABLE lin_detail
    FIELD hidID AS INT XML-NODE-TYPE "HIDDEN".

DEFINE TEMP-TABLE tLines
    FIELD OrderNo AS INT
    FIELD OrdLineNo AS INT
    FIELD hidID AS INT XML-NODE-TYPE "HIDDEN".

DEFINE TEMP-TABLE misc_detail
    FIELD hidID AS INT XML-NODE-TYPE "HIDDEN".

DEFINE TEMP-TABLE tMisc
    FIELD OrderLineNo AS INT
    FIELD hidID AS INT XML-NODE-TYPE "HIDDEN".

DEFINE DATASET ProDataSet FOR tHeader, lin_detail, tLines, misc_detail, tMisc
    DATA-RELATION r1 FOR tHeader, lin_detail RELATION-FIELDS (hidID, hidID) NESTED
    DATA-RELATION r2 FOR lin_detail, tLines RELATION-FIELDS (hidID, hidID) NESTED
    DATA-RELATION r3 FOR tLines, misc_detail RELATION-FIELDS (hidID, hidID) NESTED
    DATA-RELATION r4 FOR misc_detail, tMisc RELATION-FIELDS (hidID, hidID) NESTED.

This thread is closed