Link to home
Start Free TrialLog in
Avatar of Theo Kouwenhoven
Theo KouwenhovenFlag for Netherlands

asked on

XML response optional elements

Hi Experts,

In my RPG program I have the following parameters:
     DCL-PI *N;                  
       INPUT llikeDs(tmpl001);      
       OUTPUT likeDs(resp);
     end-pi;                    

The OUTPUT parm has 2 fields in the structure:
Dcl-ds Resp qualified;
  Number Char(15);
  Error Char(128);    
End-ds;              

On this moment both elements will be shown in the XML response
 <OUTPUT>
               <ERROR/>
               <NUMBER>12345</NUMBER>
</OUTPUT>

I like to skip the <ERRROR> element when it's not used, how to do that?
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

It is defined in the XSD
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
       <xs:element name="OUTPUT">
              <xs:complexType>
                     <xs:sequence>
[b]                            <xs:element name="ERROR" type="xs:string" minOccurs="0"></xs:element>[/b]
                            <xs:element name="NUMBER" type="xs:int"></xs:element>
                        </xs:sequence>
                 </xs:complexType>
          </xs:element>
   </xs:schema>

Open in new window

Hi Theo,  How are you mapping your response to XML?
Note, mod changed my post to code so ignore b tags in line 5 that I added for emphasize
Avatar of Theo Kouwenhoven

ASKER

gary,

DCL-PI *N;                  
       INPUT llikeDs(tmpl001);      
       OUTPUT likeDs(resp);
     end-pi;      

if condition x;
output.number = 123
else
output.error = 'err found'
endif
ASKER CERTIFIED SOLUTION
Avatar of Gary Patterson, CISSP
Gary Patterson, CISSP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Gary,

I'm not transforming to XML, just assigned an Input and output parm in the program that is automatic translated to XML.
Hi Theo.  

Yes.  I am an RPG programmer.  I see your code, and I understand what you are doing.

What I don't see is the XML transformation.  You say it is "automatic".  That means that something outside of your program is performing the transformation.  What is that?

- Gary
That is done by the iSeries webServer (I don't know how) but when I post a Soap message to the Webservice,
it enters my program in a DS (structured) and my Out-parm is returned in XML format

I discovered some more errors, so it's not so cool as I thought it was.
OK.  Afraid I can't help you until you can tell me how the XML transform is being done.  Can you ask whoever set it up?
I did the setup, just with the Wizzard on the IWS.
1. Choose Soap
2. Choose program
3. Select In-/OutParm
4. Finish
Then I used the WSDL from the properties to test with SoapUI
That's what I thought.  See my earlier comment, above 41964384, and in particular review the attached document, which explains how to handle returning an array which could have multiple elements.

Same technique applies to optional elements.
Thanks for your help,
Next question is comming up :-)