XML-INTO not "parsing" all the different values

Any IBM i topic that does not fit in another forum
Post Reply
schhub
Posts: 2
Joined: Tue Mar 14, 2023 11:42 am

XML-INTO not "parsing" all the different values

Post by schhub »

Hi to all,

This i s part of a new program

Code: Select all

dcl-s Img64      SQLTYPE(CLOB:500000);

dcl-ds MyDS                    qualified;                                       
    dcl-ds Shipment;                                                    
       dcl-ds Shipment;                                                 
          BarcodeId            char(30);                                
          BarcodeSource        char(30);                                
          Barcode              char(30);                                
       end-ds;                                                          
       Type                    char(30);                                
    end-ds;                                                             
    dcl-ds Labels;                                                      
       dcl-ds Label            Dim(2);                                  
              type             char(30);                                
              label            SQLTYPE(CLOB:500000);                    
       end-ds;                                                          
    end-ds;                                                             
End-ds;                                                                 



postResult is an xml file read on IFS by open....

read(fd_xml : %addr(rddata) : %size(rddata));

postResult = %trimr(rddata);

....

xml-into MyDS %xml(postResult: 'case=convert ns=remove +     
allowmissing=yes allowextra=yes +                             
path=Envelope/Body'+                                          
     '/CreateReverseInverseShipmentWithLabelsBcResponse'+     
     '/CreateReverseInverseShipmentWithLabelsBcResult');   

The file on IFS contains this data :

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<soap:Body>
		<CreateReverseInverseShipmentWithLabelsBcResponse xmlns="http://xx.xxx.xxx">
			<CreateReverseInverseShipmentWithLabelsBcResult>
				<Shipment>
					<Shipment>
						<BarcodeId>10770800002688</BarcodeId>
						<BarcodeSource>902</BarcodeSource>
						<BarCode>%008800010770800002688332902</BarCode>
					</Shipment>
					<Type>REVERSE</Type>
				</Shipment>
				<Labels>
					<Label>
						<type>REVERSEBIC3</type>
						<label>XlhBDQpeQ0kyOA0KXkxIMTgsOA0KXlB...</label>
					</Label>
					<Label>
						<type>PROOFBIC3</type>
						<label>XlhBDQpeQ0kyOA0KXkxIMTgsOA0KXlBPTg0KXkZUNTAwLDIwOQ0KXkEwTiwxNiwwXkZEQXR0ZW50aW9uLCBuJ291YmxpZXogcGFzIGRlIGZhaXJlIGFw...</label>
					</Label>
				</Labels>
			</CreateReverseInverseShipmentWithLabelsBcResult>
		</CreateReverseInverseShipmentWithLabelsBcResponse>
	</soap:Body>
</soap:Envelope>	

The strange thing is when the xml-into is executed i get the MyDS.Labels.Label.type(1) and MyDS.Labels.Label.type(2) with correct values, REVERSEBIC3 and PROOFBIC3, but nothing in MyDS.Labels.Label.label(1) or MyDS.Labels.Label.label(2).

I don't understand why i can't get the label content itself.

I tried with an other xml-into like this :

Code: Select all

xml-into Img64_DATA %xml(postResult:'case=convert ns=remove +   
allowmissing=yes allowextra=yes +                                  
path=Envelope/Body'+                                               
     '/CreateReverseInverseShipmentWithLabelsBcResponse'+          
     '/CreateReverseInverseShipmentWithLabelsBcResult'+            
     '/Labels/label/label'); 

This way i get the value, but only for the first occurence.

I need to get the two label values , certainly i'm doing something wrong but i dont know what.

Could you please help me figure out what i'm doing wrong ?

Thanx in advance for your help
jonboy49
Posts: 200
Joined: Wed Jul 28, 2021 8:18 pm

Re: XML-INTO not "parsing" all the different values

Post by jonboy49 »

Well, the first question is why are _you_ reading the file? That provides a whole set of error possibilities just there.

Add the option doc=file to the options string and replace the name post-result in the XML-INTO with either the full name of the file or with the name of a variable or constant containing that data.

See how that goes and come back if you still have an issue.

You can probably also simplify the DS by adding shipment to your path.
schhub
Posts: 2
Joined: Tue Mar 14, 2023 11:42 am

Re: XML-INTO not "parsing" all the different values

Post by schhub »

I solved the problem by changing the label variable type from CLOB to varchar

Code: Select all

dcl-ds CSWBR           qualified;                        
    dcl-ds Shipment;                                     
       dcl-ds Shipment;                                  
          BarcodeId            char(30);                 
          BarcodeSource        char(30);                 
          Barcode              char(30);                 
       end-ds;                                           
       Type                    char(30);                 
    end-ds;                                              
    dcl-ds Labels;                                       
       dcl-ds Label            Dim(2);                   
              type             char(30);                 
              label            VARCHAR(160000);          
       end-ds;                                           
    end-ds;                                              
End-ds;                             


All is working, but i'll have a look at the doc=file option.

Thanks for your help.
Post Reply