ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Nested XML nodes in PCML for webservices

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

  • Nested XML nodes in PCML for webservices

    Hello

    I hope somebody can help with this one.

    I want to create a webservice using IBM Web Administration for i5/OS. It is easy enough to compile the RPGLE program with PGMINFO set to *PCML and a path for the PCML file specified in INFOSTMF, and then use the PCML file to create the webservice using the Deploy New Service Wizard. The problem is that I am limited to the *Entry parameters of the RPG program for XML SOAP nodes.

    This is a problem, because the SOAP response envelope is returned in a format which is difficult to parse.


    Is there a way to edit the PCML file, or change the way the entry parameters are specified in the RPGLE, so that I can nest XML tags within one another,so that they will be easier to parse; for example:
    Code:
    <CLIENTS>
      <CLIENT>
          <SURNAME>Smith</SURNAME>
          <CLIENTNO>12345</CLIENTNO>
          <PHONE>1112224444</PHONE>
      </CLIENT>
      <CLIENT>
        <SURNAME>Jones></SURNAME>
        <CLIENTNO>12346</CLIENTNO>
        <PHONE>2223334444</PHONE>
      </CLIENT>
      . . .
    </CLIENTS>
    What I am doing now is to create a XMLString node, and then control the start and end tags myself in my program. Then within the XMLString node, I have to substitute '&lt;' for less-than (<) and '&gt;' for greater than (>), so that the IBM XML process will let it through. The program that consumes the webservice then needs to translate the XMLString back before it can parse it. It does work, but it seems a bit crazy.

    I am sure somebody must have had the same problem and found a better way to do it.

    Thank you

  • #2
    Re: Nested XML nodes in PCML for webservices

    Hello again

    I sort of figured it out now.

    I created a RPGLE program:
    Code:
    D InData          DS                  qualified               
    D  Field1                       20                            
    D  Field2                       20                            
    D  Field3                       30                            
    D  Nested                             likeds(nestdata)        
    D NestData        DS                                          
    D  NestFld1                     10                            
    D  NestFld2                     10                            
    D  NestFld3                     10                            
    D OutData         DS                  qualified               
    D  Out1                         20                            
    D  Out2                         20                            
    D  Out3                         20                            
    D  NestedO                            likeds(nestdata) dim(20)
     *                                                            
    C     *entry        Plist                                     
    C                   Parm                    InData                 
    C                   Parm                    OutData                
     /free                                                             
       OutData.Out1 = 'Field1';                                        
       OutData.Out2 = 'Field2';                                        
       OutData.Out3 = 'Field3';                                        
       OutData.NestedO(1).NestFld1 = 'Nested1.1';                      
       OutData.NestedO(1).NestFld2 = 'Nested1.2';                      
       OutData.NestedO(1).NestFld3 = 'Nested1.3';                      
       OutData.NestedO(2).NestFld1 = 'Nested2.1';                      
       OutData.NestedO(2).NestFld2 = 'Nested2.2';                      
       OutData.NestedO(2).NestFld3 = 'Nested2.3';                      
                                                                       
     /end-free                                                         
    C                   Seton                                        LR
    The PCML File looks like this:
    Code:
    <pcml version="4.0">
       <!-- RPG program: PCMLTEST  -->
       <!-- created: 2008-09-04-14.29.42 -->
       <!-- source: SAPDEV/QRPGLESRC(PCMLTEST) -->
       <!-- 10 -->
       <struct name="OUTDATA">
          <data name="OUT1" type="char" length="20" usage="inherit" />
          <data name="OUT2" type="char" length="20" usage="inherit" />
          <data name="OUT3" type="char" length="20" usage="inherit" />
          <data name="NESTEDO" type="struct" struct="NESTDATA" count="20" usage="inherit" />
       </struct>
       <!-- 6 -->
       <struct name="NESTDATA">
          <data name="NESTFLD1" type="char" length="10" usage="inherit" />
          <data name="NESTFLD2" type="char" length="10" usage="inherit" />
          <data name="NESTFLD3" type="char" length="10" usage="inherit" />
       </struct>
       <!-- 1 -->
       <struct name="INDATA">
          <data name="FIELD1" type="char" length="20" usage="inherit" />
          <data name="FIELD2" type="char" length="20" usage="inherit" />
          <data name="FIELD3" type="char" length="30" usage="inherit" />
          <data name="NESTED" type="struct" struct="NESTDATA" usage="inherit" />
       </struct>
       <program name="PCMLTEST" path="/QSYS.LIB/SAPDEV.LIB/PCMLTEST.PGM">
          <data name="INDATA" type="struct" struct="INDATA" usage="inputoutput" />
          <data name="OUTDATA" type="struct" struct="OUTDATA" usage="inputoutput" />
       </program>
    </pcml>

    Then my SOAP request looks like this:
    Code:
    <soapenv:Envelope>
        <soapenv:Body>
            <q0:pcmltest_XML>
                <q0:param0>
                    <q0:_INDATA>
                        <q0:_FIELD1>In Field 1</q0:_FIELD1>
                        <q0:_FIELD2>In Field 2</q0:_FIELD2>
                        <q0:_FIELD3>In Field 3</q0:_FIELD3>
                        <q0:_NESTED>
                            <q0:_NESTFLD1>InNested1</q0:_NESTFLD1>
                            <q0:_NESTFLD2>InNested2</q0:_NESTFLD2>
                            <q0:_NESTFLD3>InNested3</q0:_NESTFLD3>
                        </q0:_NESTED>
                    </q0:_INDATA>
                </q0:param0>
            </q0:pcmltest_XML>
        </soapenv:Body>
    </soapenv:Envelope>
    and my SOAP response looks like this:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <PCMLTEST>
        <OUTDATA>
            <OUT1>Field1</OUT1>
            <OUT2>Field2</OUT2>
            <OUT3>Field3</OUT3>
            <NESTEDO>
                <NESTFLD1>Nested1.1</NESTFLD1>
                <NESTFLD2>Nested1.2</NESTFLD2>
                <NESTFLD3>Nested1.3</NESTFLD3>
            </NESTEDO>
            <NESTEDO>
                <NESTFLD1>Nested2.1</NESTFLD1>
                <NESTFLD2>Nested2.2</NESTFLD2>
                <NESTFLD3>Nested2.3</NESTFLD3>
            </NESTEDO>
            <NESTEDO>
                <NESTFLD1></NESTFLD1>
                <NESTFLD2></NESTFLD2>
                <NESTFLD3></NESTFLD3>
            </NESTEDO>
            <NESTEDO>
                <NESTFLD1></NESTFLD1>
                <NESTFLD2></NESTFLD2>
                <NESTFLD3></NESTFLD3>
            </NESTEDO>
            <NESTEDO>
                <NESTFLD1></NESTFLD1>
                <NESTFLD2></NESTFLD2>
                <NESTFLD3></NESTFLD3>
            </NESTEDO>
            <NESTEDO>
                <NESTFLD1></NESTFLD1>
                <NESTFLD2></NESTFLD2>
                <NESTFLD3></NESTFLD3>
            </NESTEDO>
            <NESTEDO>
                <NESTFLD1></NESTFLD1>
                <NESTFLD2></NESTFLD2>
                <NESTFLD3></NESTFLD3>
            </NESTEDO>
            <NESTEDO>
                <NESTFLD1></NESTFLD1>
                <NESTFLD2></NESTFLD2>
                <NESTFLD3></NESTFLD3>
            </NESTEDO>
            <NESTEDO>
                <NESTFLD1></NESTFLD1>
                <NESTFLD2></NESTFLD2>
                <NESTFLD3></NESTFLD3>
            </NESTEDO>
            <NESTEDO>
                <NESTFLD1></NESTFLD1>
                <NESTFLD2></NESTFLD2>
                <NESTFLD3></NESTFLD3>
            </NESTEDO>
            <NESTEDO>
                <NESTFLD1></NESTFLD1>
                <NESTFLD2></NESTFLD2>
                <NESTFLD3></NESTFLD3>
            </NESTEDO>
            <NESTEDO>
                <NESTFLD1></NESTFLD1>
                <NESTFLD2></NESTFLD2>
                <NESTFLD3></NESTFLD3>
            </NESTEDO>
            <NESTEDO>
                <NESTFLD1></NESTFLD1>
                <NESTFLD2></NESTFLD2>
                <NESTFLD3></NESTFLD3>
            </NESTEDO>
            <NESTEDO>
                <NESTFLD1></NESTFLD1>
                <NESTFLD2></NESTFLD2>
                <NESTFLD3></NESTFLD3>
            </NESTEDO>
            <NESTEDO>
                <NESTFLD1></NESTFLD1>
                <NESTFLD2></NESTFLD2>
                <NESTFLD3></NESTFLD3>
            </NESTEDO>
            <NESTEDO>
                <NESTFLD1></NESTFLD1>
                <NESTFLD2></NESTFLD2>
                <NESTFLD3></NESTFLD3>
            </NESTEDO>
            <NESTEDO>
                <NESTFLD1></NESTFLD1>
                <NESTFLD2></NESTFLD2>
                <NESTFLD3></NESTFLD3>
            </NESTEDO>
            <NESTEDO>
                <NESTFLD1></NESTFLD1>
                <NESTFLD2></NESTFLD2>
                <NESTFLD3></NESTFLD3>
            </NESTEDO>
            <NESTEDO>
                <NESTFLD1></NESTFLD1>
                <NESTFLD2></NESTFLD2>
                <NESTFLD3></NESTFLD3>
            </NESTEDO>
            <NESTEDO>
                <NESTFLD1></NESTFLD1>
                <NESTFLD2></NESTFLD2>
                <NESTFLD3></NESTFLD3>
            </NESTEDO>
        </OUTDATA>
    </PCMLTEST>
    My question is now how do I suppress NESTEDO(3) through NESTEDO(20)?

    Is there a PCML equivalent to the XSLT directive <xsl:value-of select="xmlnode"> that I can use to overide the number of output nodes?

    Thank you
    Last edited by Flodge; September 4, 2008, 07:03 AM.

    Comment


    • #3
      Re: Nested XML nodes in PCML for webservices

      Hello

      Here is the answer:

      Create a field to hold the number of output nodes in the RPGLE. The field must be 10.0 type integer and must be defined in the same data structure in which the output array is defined:

      Code:
      D OutData         DS                  qualified               
      [B]D OutputNodes                   10I 0                         [/B]
      D  Out1                         20                            
      D  Out2                         20                            
      D  Out3                         20                            
      D  NestedO                            likeds(nestdata) dim(20)
      Then edit the PCML. Add an initialise property to the OutputNodes field (otherwise the webservice will complain and refuse to work) and change the value of count on the output array to be OutputNodes:

      Code:
      <pcml version="4.0">
         <!-- RPG program: PCMLTEST  -->
         <!-- created: 2008-09-05-09.56.49 -->
         <!-- source: SAPDEV/QRPGLESRC(PCMLTEST) -->
         <!-- 11 -->
         <struct name="OUTDATA">
            <data name="OUTPUTNODES" type="int" length="4" precision="31" [B]init="5"[/B]  usage="inherit" />
            <data name="OUT1" type="char" length="20" usage="inherit" />
            <data name="OUT2" type="char" length="20" usage="inherit" />
            <data name="OUT3" type="char" length="20" usage="inherit" />
            <data name="NESTEDO" type="struct" struct="NESTDATA" [B]count="OUTPUTNODES"[/B] usage="inherit" />
         </struct>
         <!-- 7 -->
         <struct name="NESTDATA">
            <data name="NESTFLD1" type="char" length="10" usage="inherit" />
            <data name="NESTFLD2" type="char" length="10" usage="inherit" />
            <data name="NESTFLD3" type="char" length="10" usage="inherit" />
         </struct>
         <!-- 2 -->
         <struct name="INDATA">
            <data name="FIELD1" type="char" length="20" usage="inherit" />
            <data name="FIELD2" type="char" length="20" usage="inherit" />
            <data name="FIELD3" type="char" length="30" usage="inherit" />
            <data name="NESTED" type="struct" struct="NESTDATA" usage="inherit" />
         </struct>
         <program name="PCMLTEST" path="/QSYS.LIB/SAPDEV.LIB/PCMLTEST.PGM">
            <data name="INDATA" type="struct" struct="INDATA" usage="inputoutput" />
            <data name="OUTDATA" type="struct" struct="OUTDATA" usage="inputoutput" />
         </program>
      </pcml>
      Then the SOAP response looks like this:
      Code:
      <soapenv:Envelope>
          <soapenv:Body>
              <ns:pcmltest_XMLResponse>
                  <ns:return>
      <?xml version="1.0" encoding="UTF-8"?>
                      <PCMLTEST>
                          <OUTDATA>
                              <OUTPUTNODES>2</OUTPUTNODES>
                              <OUT1>Field1</OUT1>
                              <OUT2>Field2</OUT2>
                              <OUT3>Field3</OUT3>
                              <NESTEDO>
                                  <NESTFLD1>Nested1.1</NESTFLD1>
                                  <NESTFLD2>Nested1.2</NESTFLD2>
                                  <NESTFLD3>Nested1.3</NESTFLD3>
                              </NESTEDO>
                              <NESTEDO>
                                  <NESTFLD1>Nested2.1</NESTFLD1>
                                  <NESTFLD2>Nested2.2</NESTFLD2>
                                  <NESTFLD3>Nested2.3</NESTFLD3>
                              </NESTEDO>
                          </OUTDATA>
                      </PCMLTEST>
                  </ns:return>
              </ns:pcmltest_XMLResponse>
          </soapenv:Body>
      </soapenv:Envelope>
      Pretty good hey?

      I hope this of benefit to somebody (besides me).

      Comment


      • #4
        Re: Nested XML nodes in PCML for webservices

        The internet is wonderful for talking to myself.

        Comment


        • #5
          Re: Nested XML nodes in PCML for webservices

          Scintillating conversion boet
          Last edited by kitvb1; September 22, 2008, 02:35 AM.
          Regards

          Kit
          http://www.ecofitonline.com
          DeskfIT - ChangefIT - XrefIT
          ___________________________________
          There are only 3 kinds of people -
          Those that can count and those that can't.

          Comment

          Working...
          X