Returning Multiple instances of an element

Help
2011-02-10
2013-06-06
  • Thurston Roeth

    Thurston Roeth - 2011-02-10

    Hi - New to Nusoap and intermediate on PHP.
    <data>
    <record>
       <part1>
          <element1></element1>
          <element2></element1>
       </part1>
       <part2>
          <element3></element1>
          <element4></element1>
        </part2>
    </record>
    <record>
       <part1>
          <element1></element1>
          <element2></element1>
       </part1>
       <part2>
          <element3></element1>
          <element4></element1>
        </part2>
    </record>
    .
    .
    . for _n _records
    .
    </data>

    I'm using the WSDL & Complex types example from :   http://www.scottnichol.com/soap/nusoapprogwsdl.html (Defining New Data Structures about 1/2 way down the page)

    but cannot figure out how to return more than one <greeting> element .
    Tried passing in arrays but that doesnt seem to work.

    Snipits:

    $server->wsdl->addComplexType(
        'SweepstakesGreeting',
        'complexType',
        'struct',
        'all',
        '',
        array(
            'greeting' => array('name' => 'greeting', 'type' => 'xsd:string'),
            'winner' => array('name' => 'winner', 'type' => 'xsd:boolean')
        )
    );

    return array(
                    'greeting' => $greeting,
                    'winner' => $winner
                    );

    Anyone have any idea how to do this?

     
  • Scott Nichol

    Scott Nichol - 2011-02-11

    You need to get the correct WSDL and structure the return value properly.  To get the correct WSDL, I personally prefer to write the WSDL separately and pass the path of the file to the nusoap_server constructor.  You may be able to do it with addComplexType calls, too.  You need to start at the innermost nesting of the XML and work your way out.  In this case, define a complexType part1 containing element1 and element2, a complexType part2 containing element3 and element4, a complexType record containing a part1 and part2, and a complexType data containing 0 to many records.

    To return the XML structure above, you would have something like

    $record = array('part1' => array('element1' => '', 'element2' => ''), 'part2' => array('element3' => '', 'element4' => ''));

    $record = array('part1' => array('element1' => '', 'element2' => ''), 'part2' => array('element3' => '', 'element4' => ''));

    $data = array('record' => $record);

    return $data; // or return array('data' => $data);

     

Log in to post a comment.