XML-INTO error RNX0305, reason code 1

Discussions relating to writing software in ILE RPG (RPG IV). This includes both fixed and free format RPG.
Post Reply
lburkett
Posts: 4
Joined: Tue Aug 10, 2021 4:18 am

XML-INTO error RNX0305, reason code 1

Post by lburkett »

The XML-INTO instruction in my program below gets error RNX0305, "The specified path to the XML element was not found in the XML document." The value of RESPONSE is

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/e'
nvelope/"><soap:Body><ns2:cstitmwebResponse xmlns:ns2="http:'
//cstitmweb.wsbeans.iseries/xsd"><return><COMPANY>1</COMPANY'
><CONTRACT> </CONTRACT><CUSTCODE> </CUSTCODE><CUSTOMER>9'
876543210</CUSTOMER><EXPIREDATE>6212022</EXPIREDATE><FUNCTIO'
N>E</FUNCTION><ITEM>921530D </ITEM><ITEMC'
ODE> </ITEMCODE><PRICECODE>D</PRICECODE><PRICEDISCCODE>0</PR'
ICEDISCCODE><PRICELIST>0</PRICELIST><PRICEPCT>1.00000</PRICE'
PCT><QTYLIMIT>0.000</QTYLIMIT><STARTDATE>6192022</STARTDATE>'
<TYPE>CI</TYPE></return></ns2:cstitmwebResponse></soap:Body>'
</soap:Envelope> '

Code: Select all

H DFTACTGRP(*NO) BNDDIR('HTTPAPI')    
                                      
 /copy qrpglesrc,httpapi_h            
                                      
D return          ds                  
D  COMPANY                       2  0 
D  CONTRACT                      5    
D  CUSTCODE                      1    
D  CUSTOMER                     10  0 
D  EXPIREDATE                    8  0 
D  FUNCTION                      1    
D  ITEM                         27    
D  ITEMCODE                      1    
D  PRICECODE                     1    
D  PRICEDISCCODE                 1    
D  PRICELIST                     1    
D  PRICEPCT                      4  2                
D  QTYLIMIT                      1  0                
D  STARTDATE                     8  0                
D  TYPE                          2                   
                                                     
D response        s           1000    varying        
D soap            s           1000    varying        
D url             s            100    varying        
                                                     
  http_debug(*ON);                                   
                                                     
  url = 'http://192.168.1.200:10021/web/services/+   
          CSTITMWEBService/CSTITMWEB';               
                                                     
  http_setOption('SoapAction': '""');                
                                                     
  soap = '<soapenv:Envelope +                                   
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" + 
     xmlns:xsd="http://cstitmweb.wsbeans.iseries/xsd"> +        
       <soapenv:Header/> +                                      
       <soapenv:Body> +                                         
        <xsd:cstitmweb> +                                       
           <arg0> +                                             
              <_COMPANY>01</_COMPANY> +                         
              <_CONTRACT> </_CONTRACT>+                         
              <_CUSTCODE> </_CUSTCODE>+                         
              <_CUSTOMER>9876543210</_CUSTOMER> +               
              <_EXPIREDATE>06212022</_EXPIREDATE> +             
              <_FUNCTION></_FUNCTION> +                         
              <_ITEM>921530D</_ITEM> +                          
              <_ITEMCODE> </_ITEMCODE> +                        
              <_PRICECODE>D</_PRICECODE> +                      
              <_PRICEDISCCODE>0</_PRICEDISCCODE> +        
              <_PRICELIST>0</_PRICELIST> +                
              <_PRICEPCT>1.00</_PRICEPCT> +               
              <_QTYLIMIT>0</_QTYLIMIT> +                  
              <_STARTDATE>06192022</_STARTDATE> +         
              <_TYPE>CI</_TYPE> +                         
           </arg0> +                                      
        </xsd:cstitmweb> +                                
     </soapenv:Body> +                                    
  </soapenv:Envolope>';                                   
                                                          
  response = http_string( 'POST': URL: SOAP: 'text/xml'); 
                                                          
  response =  %scanrpl('<_' : '<' : response);            
  response =  %scanrpl('</_' : '</' : response);          
                                                          
  xml-into return %xml(response: 'case=any ns=remove'); 
                                                        
  *inLR = *on;                                          
  return;  
jonboy49
Posts: 206
Joined: Wed Jul 28, 2021 8:18 pm

Re: XML-INTO error RNX0305, reason code 1

Post by jonboy49 »

Well as the error message says the path is incorrect - in fact you haven't specified a path at all.

Your code would work if your XML looked like this:

Code: Select all

<return>
    <COMPANY>1</COMPANY>
    <CONTRACT></CONTRACT>
    <CUSTCODE></CUSTCODE>
    <CUSTOMER>9876543210</CUSTOMER>
    ...
But it has (namespaces removed as per your code)

Code: Select all

<Envelope>
    <Body>
        <cstitmwebResponse >
            <return>
RPG can't just "hunt" for where <return> starts because there could be multiple <return> elements in different parts of the structure. So you have to tell ii where to start looking via a path= option on the XML-INTO. So in your case, you need to add something like path=Envelope/Body/cstitmwebResponse/return alongside your case=any etc..
lburkett
Posts: 4
Joined: Tue Aug 10, 2021 4:18 am

Re: XML-INTO error RNX0305, reason code 1

Post by lburkett »

That fixed it.

Is there a situation when the "path=" option is not required?
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: XML-INTO error RNX0305, reason code 1

Post by Scott Klement »

When you want to process the entire document rather than just a portion of it, path= isn't (or shouldn't be) required.

In your case you want to skip past the Envelope, Body, cstitmwebResponse and return elements, though... so you need it to tell XML-INTO what to skip
lburkett
Posts: 4
Joined: Tue Aug 10, 2021 4:18 am

Re: XML-INTO error RNX0305, reason code 1

Post by lburkett »

Thank you.
Post Reply