Xml Read

Posted by kadirduman on 21-Mar-2014 03:29

how can i read xml for dataset

sample 

<ns0:ProductResult xmlns:ns0="http://tempuri.org/">

<ns1:ErrorMessage>string-value</ns1:ErrorMessage>

        <ns1:Booking>

        <ns1:AmountPaid>decimal-value</ns1:AmountPaid>

                <ns1:BookingProducts>

                        <ns1:AllowPrintAtHome>boolean-value</ns1:AllowPrintAtHome>

                <ns1:Seats>

                        <ns1:Seat>

                                 <ns1:AllocationId>string-value</ns1:AllocationId>

                        <ns1:/Seat>

                <ns1:/Seats>

                <ns1:/BookingProducts>

        <ns1:/Booking>

<ns0:/ProductResult>

All Replies

Posted by Dileep Dasa on 21-Mar-2014 03:58

If I understood correctly, you are looking for a method to read an XML into a dataset. This is possible with READ-XML() method.

Here is  an example:

DEFINE VARIABLE cSourceType             AS CHARACTER NO-UNDO.

DEFINE VARIABLE cReadMode               AS CHARACTER NO-UNDO.

DEFINE VARIABLE lOverrideDefaultMapping AS LOGICAL   NO-UNDO.

DEFINE VARIABLE cFile                   AS CHARACTER NO-UNDO.

DEFINE VARIABLE cSchemaLocation         AS CHARACTER NO-UNDO.

DEFINE VARIABLE cFieldTypeMapping       AS CHARACTER NO-UNDO.

DEFINE VARIABLE cVerifySchemaMode       AS CHARACTER NO-UNDO.

DEFINE VARIABLE lRetOK                  AS LOGICAL   NO-UNDO.

DEFINE VARIABLE hDSet                   AS HANDLE    NO-UNDO.

CREATE DATASET hDSet.

ASSIGN  

cSourceType             = "file"  

cFile                   = "dset.xml"  

cReadMode               = "empty"  

cSchemaLocation         = "cust-ord-inv.xsd"  

lOverrideDefaultMapping = ?  

cFieldTypeMapping       = ?  

cVerifySchemaMode       = ?.

lRetOK = hDSet:READ-XML(cSourceType, cFile, cReadMode, cSchemaLocation,  lOverrideDefaultMapping, cFieldTypeMapping, cVerifySchemaMode).

Posted by kadirduman on 21-Mar-2014 04:26

i dont have xsd files

sample code here

DEFINE TEMP-TABLE ProductResult NO-UNDO

   FIELD ErrorMessage          AS CHARACTER.

DEFINE TEMP-TABLE Booking NO-UNDO

   FIELD AmountPaid                AS DECIMAL.

DEFINE TEMP-TABLE Seat NO-UNDO XML-NODE-NAME "Seats"

   FIELD AllocationId AS CHARACTER

DEFINE DATASET Product FOR ProductResult, Booking, Seat.

DATASET Product:READ-XML("longchar",        /* SourceType             */

                                   vResults,          /* File                   */

                                   "EMPTY",          /* ReadMode               */

                                   ?,                 /* SchemaLocation         */

                                   ?,                 /* OverrideDefaultMapping */

                                   ?,                 /* FieldTypeMapping       */

                                   ?).                /* VerifySchemaMode       */

seat temptable not adding record but other temptable is record available.

how can add using read-xml method for seat temptable record.

Posted by Dileep Dasa on 21-Mar-2014 04:56

I just tried your code and I am able to see records in "Seat" temp-table. Are you seeing any errors? Also, can you paste snippet of your XML file?

Posted by kadirduman on 21-Mar-2014 06:17

 <ProductResult xmlns="http://tempuri.org/" xmlns:a="schemas.datacontract.org/" xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns:s="schemas.xmlsoap.org/.../">

 <a:Result>Success</a:Result>

 <a:Booking>

 <a:AmountToPay>75.0000</a:AmountToPay>

 <a:BookingProducts>

 <a:BookingProduct>

 <a:Quantity>1</a:Quantity>

 <a:Seats>

 <a:Seat>

 <a:AllocationId>13103-e716-453b-96f-34c6c501fd</a:AllocationId>

 <a:BlockName>1</a:BlockName>

 <a:Number>4</a:Number>

 <a:Row>1</a:Row>

 <a:Status>0</a:Status>

 </a:Seat>

 </a:Seats>

 <a:Session i:nil="true" />

 <a:Start>2014-05-17T20:00:00</a:Start>

 </a:BookingProduct>

 </a:BookingProducts>

 <a:VouchersCollected>false</a:VouchersCollected>

 </a:Booking>

 <a:BookingId>3af3ee-d6b0-e31-99c-00d0a3a07</a:BookingId>

 <a:BookingProductIds xmlns:b="schemas.microsoft.com/.../Arrays" i:nil="true" />

 <a:BookingStatus>Pending</a:BookingStatus>

 <a:UnseatedAllocationIds xmlns:b="schemas.microsoft.com/.../Arrays" />

 </ProductResult>


Posted by Jean Richert on 21-Mar-2014 06:56

Hi guys,

We just saw your posts with a good amount of code being shared and just wanted to let you know our Community does have a code highlighter. Follow this link to find out how to use it.

Posted by kadirduman on 21-Mar-2014 07:33

I have solved this problem

thank you

This thread is closed