ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

xml-into not clearing receiver

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

  • xml-into not clearing receiver

    might this just be a possible "pay-attention-thing" when using XML-INTO
    (it is friday the 13th with a reason today ?)

    i'm having a single program that :
    1. reads all xml-documents from a certain folder
    2. the xml-data is read into a data-structure using xml-into
    3. do something with the data

    DS-declaration :

    Code:
          * XML FORMAT ********************************************************************************
         d
         d ds_namval       ds
         d fld_nam                       20
         d fld_val                       20
         d
         d ds_fld          ds                  qualified
         d fld                                 dim(30) likeds(ds_namval)
         d
    the code that reads in the xml into the datastructure ds_fld
    Code:
            z_text = 'FILE ' + %trim(file_b);
            write ltext;
    
            xmlfile = %trimr(w_soap_fil);
            options = 'doc=file +
                       path=header/detail +
                       ccsid=best +
                       case=any +
                       allowextra=yes +
                       allowmissing=yes' ;
    
            monitor;
             //ds_fld = *blanks;
             xml-into ds_fld %xml(xmlfile:options);
    
             i = 1;
             dow i < 30 and ds_fld.fld(i).fld_nam <> *blanks;
              z_text = ds_fld.fld(i).fld_nam + ' ' + ds_fld.fld(i).fld_val;
              write ltext;
    
              i = i + 1;
             enddo;
            on-error *all;
             z_text = 'Ongeldige XML-inhoud';
             write ltext;
            endmon;
    2 example-files that has been used

    FILE1.XML
    Code:
    <header>
     <detail>
      <fld>
       <fld_nam>A</fld_nam>
       <fld_val>1</fld_val>
      </fld>
      <fld>
       <fld_nam>B</fld_nam>
       <fld_val>2</fld_val>
      </fld>
     </detail>
    </header>
    FILE2.XML
    Code:
    <header>
     <detail>
      <fld>
       <fld_nam>C</fld_nam>
       <fld_val>3</fld_val>
      </fld>
     </detail>
    </header>
    when executing the program the output was
    Code:
    FILE file1.xml       
    A                    1
    B                    2
    FILE file2.xml       
    C                    3
    B                    2
    so the ds_fld-receiver from the xml-into is not cleared from the first xml-into-operation
    the B-value from the first operation remains

    a forced clear from the DS is suitable to be executed before the xml-into is done

    or how do you encode the "dow"-loop do detect the end of the data that has been read into the DS ?
    maybe my check on the *blanks is not the right way

  • #2
    XML-INTO has never blanked out the receiver variable -- nothing new about that. In fact, I've found this to be very useful at times because I'll load some data from one source, and some data from another source.

    Please consider using the 'countprefix' feature to determine how many array elements were loaded, and modify your loop to use the count field.

    Comment


    • #3
      thanks scott (again)

      that countprefix will do the thing for me i guess
      i made this modifications :
      Code:
       * XML FORMAT ********************************************************************************
      d                                                                                            
      d ds_namval       ds                                                                          
      d fld_nam                       20                                                            
      d fld_val                       20                                                            
      d                                                                                            
      d ds_fld          ds                  qualified                                              
      d fld                                 dim(30) likeds(ds_namval)                              
      [COLOR=#FF0000]d cntfld                        10  0                                                         [/COLOR]
      Code:
      xmlfile = %trimr(w_soap_fil);  
      options = 'doc=file +          
                 path=header/detail +
                 ccsid=best +        
                 case=any +          
                 allowextra=yes +    
                 allowmissing=yes +  
      [COLOR=#FF0000]countprefix=cnt[/COLOR]';    
      
      monitor;                                                      
       //ds_fld = *blanks;                                          
       xml-into ds_fld %xml(xmlfile:options);                      
      
      [COLOR=#FF0000]for i=1 to ds_fld.cntfld;[/COLOR]                                    
        z_text = ds_fld.fld(i).fld_nam + ' ' + ds_fld.fld(i).fld_val;
        write ltext;                                                
       endfor;        
      on-error *all;                  
       z_text = 'Ongeldige XML-inhoud';
       write ltext;                  
      endmon;
      the generated output is now the desired one
      Code:
      FILE file1.xml      
      A                    1
      B                    2
      FILE file2.xml      
      C                    3
      additional information can be found here :

      Last edited by pet0etie; December 16, 2019, 07:02 AM.

      Comment

      Working...
      X