ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Error defining Data Structure for XML

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error defining Data Structure for XML

    Hi,

    I have the XML attached and I am defining it as follows.


    0045.00 *------------------------------------------------------------------------*
    0046.00 * XML Data Definition *
    0047.00 *------------------------------------------------------------------------*
    0048.00 DEnvelope DS Qualified
    0049.00 DBody
    0050.00 D LikeDs(BodyDS)
    0051.00
    0052.00
    0053.00 DBodyDS DS Qualified
    0054.00 DListBatchFiles2018Response...
    0055.00 D LikeDs(ListBatchFiles2018ResponseDS)
    0056.00
    0057.00 DListBatchFiles2018ResponseDS...
    0058.00 D DS Qualified
    0059.00 DListBatchFilesResult...
    0060.00 D LikeDs(ListBatchFilesResultDS)
    0061.00
    0062.00 DListBatchFilesResultDS...
    0063.00 D DS Qualified
    0064.00 DBatchFileInfo...
    0065.00 D LikeDs(BatchFileInfoDS)
    0066.00 D Dim(5)
    0067.00
    0068.00 DBatchFileInfoDS DS
    0069.00 DBatchFileInfoId...
    0070.00 D 3
    0071.00 DBatchid...
    0072.00 D 36
    0073.00 DDate...
    0074.00 D 22
    0075.00 DFileName...
    0076.00 D 50
    0077.00 DFileType...
    0078.00 D 16
    0079.00 DParticipantNumber...
    0080.00 D 7


    I have the problem with the matrix, since I don't think I'm doing it properly.

    0164.00 * Work Fields
    0165.00 D icase s 8a inz('case=any')
    0166.00 D iallow1 s 14a inz('allowextra=yes')
    0167.00 D iallow2 s 16a inz('allowmissing=yes')
    0168.00 D iallow3 s 16a inz('ns=remove')
    0169.00 D options S 100A
    0170.00
    0171.00 /free
    0172.00
    0173.00 options = icase + ' ' + iallow1 + ' ' + iallow2 + ' ' + iallow3;
    0174.00 XML-INTO Envelope %XML(pDataIn: options);

    When he decodes the message he's reading it to me like this, and I don't think it's quite right

    ENVELOPE.BODY.LISTBATCHFILES2018RESPONSE.LISTBATCH FILESRESULT.BATCHFILEINFO.BATCHFILEINFOID(1) =
    .
    .
    .
    .
    ENVELOPE.BODY.LISTBATCHFILES2018RESPONSE.LISTBATCH FILESRESULT.BATCHFILEINFO.BATCHFILEINFOID(1) =.
    .
    .
    .

    I think it should be:

    ENVELOPE.BODY.LISTBATCHFILES2018RESPONSE.LISTBATCH FILESRESULT.BATCHFILEINFO(1).BATCHFILEINFOID(1) =
    .
    .
    .
    .
    ENVELOPE.BODY.LISTBATCHFILES2018RESPONSE.LISTBATCH FILESRESULT.BATCHFILEINFO(2).BATCHFILEINFOID(1) =.
    .
    .
    .
    I'm sure it's silly, but I'm not seeing it. Grateful for your help.
    Attached Files

  • #2
    For starters, you will find it much simpler to get the ds right if you code it in free-form like this:
    Code:
            //------------------------------------------------------------------------* 
            // XML Data Definition  
            //------------------------------------------------------------------------* 
    
            Dcl-ds Envelope Qualified; 
              Dcl-ds Body; 
                Dcl-ds ListBatchFilesResult; 
                  Dcl-ds  BatchFileInfo  Dim(5); 
                    BatchFileInfoId    char(3);
                    Batchid            char(36); 
                    Date               char(22);
                    FileName           char(50); 
                    FileType           char(16); 
                    ParticipantNumber  char(7); 
                  End-ds;
                End-ds;
              End-ds;
            End-ds;
    It makes it so much easier to see if the structure matches the XML.

    In your "it should be" you use two sets of parens ...BATCHFILEINFO(1).BATCHFILEINFOID(1)... but there is only one array (BatchFileInfo) because there is only one repeating element.

    You are not capturing any of the data at levels higher than the BatchFileInfo element, so you could simplify the whole thing to this:
    Code:
    Dcl-ds  BatchFileInfo  Dim(5); 
            BatchFileInfoId    char(3);
            Batchid            char(36); 
            Date               char(22);
            FileName           char(50); 
            FileType           char(16); 
            ParticipantNumber  char(7); 
     End-ds;
    And then use XML-INTO BatchFileInfo with a path=/ENVELOPE/BODY/LISTBATCHFILES2018RESPONSE/LISTBATCHFILESRESULT/BATCHFILEINFO (or something like that)

    The path will force the parser down to the actual start point you want. It also has the added benefit that since you are targeting an array the element count for the number loaded will be i the PSDS.

    P.S. You should be able to remove both the missing and extra options if this is really what the file looks like - always good to avoid them if you can.

    Comment


    • #3
      Originally posted by JonBoy View Post
      For starters, you will find it much simpler to get the ds right if you code it in free-form like this:
      Code:
      //------------------------------------------------------------------------*
      // XML Data Definition
      //------------------------------------------------------------------------*
      
      Dcl-ds Envelope Qualified;
      Dcl-ds Body;
      Dcl-ds ListBatchFilesResult;
      Dcl-ds BatchFileInfo Dim(5);
      BatchFileInfoId char(3);
      Batchid char(36);
      Date char(22);
      FileName char(50);
      FileType char(16);
      ParticipantNumber char(7);
      End-ds;
      End-ds;
      End-ds;
      End-ds;
      It makes it so much easier to see if the structure matches the XML.

      In your "it should be" you use two sets of parens ...BATCHFILEINFO(1).BATCHFILEINFOID(1)... but there is only one array (BatchFileInfo) because there is only one repeating element.

      You are not capturing any of the data at levels higher than the BatchFileInfo element, so you could simplify the whole thing to this:
      Code:
      Dcl-ds BatchFileInfo Dim(5);
      BatchFileInfoId char(3);
      Batchid char(36);
      Date char(22);
      FileName char(50);
      FileType char(16);
      ParticipantNumber char(7);
      End-ds;
      And then use XML-INTO BatchFileInfo with a path=/ENVELOPE/BODY/LISTBATCHFILES2018RESPONSE/LISTBATCHFILESRESULT/BATCHFILEINFO (or something like that)

      The path will force the parser down to the actual start point you want. It also has the added benefit that since you are targeting an array the element count for the number loaded will be i the PSDS.

      P.S. You should be able to remove both the missing and extra options if this is really what the file looks like - always good to avoid them if you can.
      Thank you very much for your response, I have not been able to do it satisfactorily with your statement.
      For some reason it gives me XML error code PARSER code 1, and I can't understand why.

      Comment


      • JonBoy
        JonBoy commented
        Editing a comment
        Can you show your version of the code including the XML-INTO and options values. Otherwise can't begin to guess.

    • #4
      I don't kn ow what you have done wrong in your code - but this is working for me using your XML.

      Code:
      Ctl-Opt  DftActGrp(*No);
      
      Dcl-ds  statusInfo  PSDS;
         elementCount int(20)  Pos(372)
      End-Ds;
      
      Dcl-ds  BatchFileInfo  Qualified  Dim(5);
          BatchFileInfoId    char(3);
          Batchid            char(36);
          Date               char(22);
          FileName           char(50);
          FileType           char(16);
          ParticipantNumber  char(7);
      End-ds;
      
      Dcl-s  options  varchar(200);
      
      Dcl-s  xmlFile  varchar(60)  Inz('/Home/Paris/XMLStuff/churro7.xml');
      
      options = 'path=Envelope/Body/ListBatchFiles2018Response/' +
                 'ListBatchFilesResult/BatchFileInfo ' +
                 'doc=file ns=remove case=any';
      
      XML-INTO BatchFileInfo %XML( xmlFile : options );
      
      Dsply ('Found ' + %Char(elementCount) + ' items' );
      
      *InLr = *On;

      Comment


      • #5
        Originally posted by JonBoy View Post
        I don't kn ow what you have done wrong in your code - but this is working for me using your XML.

        Code:
        Ctl-Opt DftActGrp(*No);
        
        Dcl-ds statusInfo PSDS;
        elementCount int(20) Pos(372)
        End-Ds;
        
        Dcl-ds BatchFileInfo Qualified Dim(5);
        BatchFileInfoId char(3);
        Batchid char(36);
        Date char(22);
        FileName char(50);
        FileType char(16);
        ParticipantNumber char(7);
        End-ds;
        
        Dcl-s options varchar(200);
        
        Dcl-s xmlFile varchar(60) Inz('/Home/Paris/XMLStuff/churro7.xml');
        
        options = 'path=Envelope/Body/ListBatchFiles2018Response/' +
        'ListBatchFilesResult/BatchFileInfo ' +
        'doc=file ns=remove case=any';
        
        XML-INTO BatchFileInfo %XML( xmlFile : options );
        
        Dsply ('Found ' + %Char(elementCount) + ' items' );
        
        *InLr = *On;
        I'm probably missing something to see, I take all your code and compile it and it gives me an error 30.

        *RNF3221 30 1 A nested data structure subfield cannot be defined when the
        parent data structure is not qualified.

        * * * * * E N D O F M E S S A G E S U M M A R Y * * * * *

        Comment


        • #6
          I attached an image of the error, change the order of the DS and it gives me an error 20 that I don't see any sense.

          Thank you for your time, it is probably very easy, but I do not finish seeing it.
          Attached Files

          Comment


          • #7
            There's a semi-colon missing at the end of the definition for elementCount in the PSDS structure. It must have got dropped during copy/paste.

            Comment


            • #8
              Originally posted by JonBoy View Post
              There's a semi-colon missing at the end of the definition for elementCount in the PSDS structure. It must have got dropped during copy/paste.
              it was that...

              Now see how I read that. Thanks JonBoy

              Comment

              Working...
              X