Reading XML into Temp-table

kirsch59

Member
I'm running WebSpeed 10.1C on a Windows 2008 server.

I would like to use XML-READ to read an XML file and store it in a temp-table. I'm not sure how to define a static temp-table using the following XML:
Code:
<GetCategoryChildrenResponse xmlns="http://tempuri.org/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
<GetCategoryChildrenResult  xmlns:a="http://schemas.datacontract.org/2004/07/Logicblock.Commerce.Domain" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:Category>
             <a:Description></a:Description>
             <a:Id>cf7e755e-1934-42bb-beb8-def1d4d8d682</a:Id>
            <a:Name>Cloth Duct Tapes</a:Name>
            <a:ParentId>03bf3128-cb61-463f-85df-8e132e22d693</a:ParentId>
       </a:Category>
       <a:Category>
           <a:Description></a:Description>
           <a:Id>dd931778-d9fc-4bc0-ad52-d36aa5e8dc77</a:Id>
           <a:Name>Doublecoated Tapes</a:Name>
           <a:ParentId>03bf3128-cb61-463f-85df-8e132e22d693</a:ParentId>
       </a:Category>
       <a:Category>
           <a:Description></a:Description>
           <a:Id>184ddef3-26af-4c05-b333-0be640214f84</a:Id>
           <a:Name>Electrical Tapes</a:Name>
           <a:ParentId>03bf3128-cb61-463f-85df-8e132e22d693</a:ParentId>
       </a:Category>
    </GetCategoryChildrenResult>
</GetCategoryChildrenResponse>

I'm not sure how to define the <Category> data element in a temp-table definition.

Here's my temp-table definition with the READ-XML command:

Code:
def temp-table t-GetCategoryChildren undo
     xml-node-name 'GetCategoryChildrenResult'
     field Category as char  /* not sure if correct */
     field Description  as char
     field Id  as char
     field Name  as char
     field Parentid  as char
                index k-GetRootCategories is primary unique Id.
 
  v-return-mode = TEMP-TABLE t-GetRootCategories:READ-XML("FILE", "data.xml", "EMPTY", ?,?,?,?).

I received a valid return code on the READ-XML but there is only a blank record in t-GetCategoryChildren.
If I remove <a:Category></a:Category> from the XML I'm able to store only the last record in t-GetCategoryChildren.

Any idea what's causing the problem?

Thanks for your help.
 

Stefan

Well-Known Member
Wrap your temp-table in a dataset:

Code:
DEFINE TEMP-TABLE ttCategory NO-UNDO XML-NODE-NAME 'Category'
   FIELD Description AS CHAR
   FIELD Id          AS CHAR
   FIELD Name        AS CHAR
   FIELD Parentid    AS CHAR
   .

DEFINE DATASET dsGCR XML-NODE-NAME "GetCategoryChildrenResult" FOR ttCategory.

DATASET dsGCR:READ-XML( "FILE", "c:\temp\cat.xml", ?, ?,?,?,? ).

DEF VAR lcc AS LONGCHAR NO-UNDO.

DATASET dsGCR:WRITE-XML( "longchar", lcc, TRUE ).

MESSAGE STRING( lcc ) VIEW-AS ALERT-BOX.
 
Top