简体   繁体   中英

XML-INTO fails in presence of self-closing tag

I am successfully using xml-into in many applications, but sometimes the XML answer of a web service is like this:

<?xml version="1.0" encoding="utf-8"?>
<InfoLabel>
<Parcel>
<SiglaMittente>E3</SiglaMittente>
<NumeroSpedizione>800000009</NumeroSpedizione>
<TotaleColli>11</TotaleColli>
<TipoCollo />
<SiglaSedeDestino />
<DenominazioneMittente>GLS BOLOGNA</DenominazioneMittente>
<DenominazioneDestinatario>PROVA ETICHETTE</DenominazioneDestinatario>
<IndirizzoDestinatario>VIA XXX</IndirizzoDestinatario>
<CittaDestinatario>MILANO</CittaDestinatario>
<ProvinciaDestinatario>MI</ProvinciaDestinatario>
<DataSpedizione>03/03/20</DataSpedizione>
<DescrizioneSedeDestino>GLS Check</DescrizioneSedeDestino>
...other xml data..
</Parcel>
<Parcel>  
...other xml data..
</Parcel>
</InfoLabel>

where the difference is the presence of self-closing tags (likeTipoCollo in the example). Other web services usually return both opening and closing tags with a blank inside.

When xml-into is executed it breaks with this error:

RNX0353 - The XML document does not match the RPG variable; reason code 8.

where

8. The XML document contains data that cannot be successfully assigned to the RPG variable. The RPG status code associated with the failure is 105.  The exact subfield for which the error was detected is "infolabel.parcel(1).tipocollo"  

The data structure is defined like this:

dcl-ds DsInfoLabel qualified inz;            
 SiglaMittente          char(2) inz;          
 NumeroSpedizione       zoned(9: 0) inz;      
 TotaleColli            zoned(2: 0) inz;      
 TipoCollo              zoned(1: 0) inz;      
 SiglaSedeDestino       char(4) inz;          
... other fields...
end-ds;                                        
dcl-ds InfoLabel qualified inz;                
 NumParcel int(10) inz;     
 Parcel likeds(DsInfoLabel) dim(99);          
end-ds;           

This is the operation code:

xml-into(e) InfoLabel %xml(resmsg_DATA: xmlopts); 
where
xmlopts='doc=string trim=all case=any allowmissing=yes allowextra=yes path=InfoLabel countprefix=Num' 

The system is running V7R2 version.

As far as I know, there isn't any other option that can be set to avoid this situation. Also, this web service must be used as-is.

Is there something else I can do?

Yes, I found a workaround, it doesn't explain why but this way data can be retrieved without error: instead of zoned the subfield TotaleColli is now defined char.

Thank you

It turns out that RPG status 105 means "Invalid characters in character to numeric conversion functions".

So "the parser is returning a value that cannot be converted to a number. In this case the parser is retuning a space and %Dec (which is effectively being used under the covers) cannot convert blanks to zero. IBM have been asked to change this but for now we are stuck with it."; these are not my words: an expert helped me.

The solution is to define character fields for data that might not be set.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM