Re: How to access/parse an associative/hashed array as responce using mozilla's SOAP client in javascript from the SOAPPropertyBag?

[email protected] Tue, 26 Jun 2007 09:52:46 -0700
Newsgroups gmane.comp.mozilla.devel.xml
Organization http://groups.google.com
Message-ID <[email protected]>
I just found that on the server side (php5) the hashed/associative
array gets serialized as a ns2:map in the soap body:
The php5 server-side array ("EntityId" => "Relations", "AttributeId"
=> "RelationsID") becomes:

<SOAP-ENV:Body>
- <ns1:getConfedJoinTreeResponse>
- <return xsi:type="ns2:Map">
- <item>
  <key xsi:type="xsd:string">EntityId</key>
  <value xsi:type="xsd:string">Relations</value>
  </item>
- <item>
  <key xsi:type="xsd:string">AttributeId</key>
  <value xsi:type="xsd:string">RelationsID</value>
  </item>
  </return>
  </ns1:getConfedJoinTreeResponse>
  </SOAP-ENV:Body>

I'm able to access the last item by using the following code:

...
var returnObject = soapcall.invoke();
returnObject.getParameters(false, {})[0].value.item.value

but I don't seem to have a way to iterate/loop through the array or
access the first item of the array.

Even php5 objects/classes seem to be better accessible since they get
serialized to SOAP-ENC:Structs (this is probably the fault of php's
soap implementation), but again there seems to be no way to iterate/
loop through the properties and/or values of the returned object from
the client (mozilla, javascript) side.

For what it's worth;
class MyAttributesClass {
    public $attrib1 = 'Inhalt 1';
    public $attrib2 = Array("EntityId" => "Relations");
    public $attrib3 = 'Inhalt 3';
    public $attrib4 = 'Inhalt 4';
    public $attrib5 = 'Inhalt 5';

}

gets serialized to;

<SOAP-ENV:Body>
- <ns1:getConfedJoinTreeResponse>
- <return xsi:type="SOAP-ENC:Struct">
  <attrib1 xsi:type="xsd:string">Inhalt 1</attrib1>
- <attrib2 xsi:type="ns2:Map">
- <item>
  <key xsi:type="xsd:string">EntityId</key>
  <value xsi:type="xsd:string">Relations</value>
  </item>
  </attrib2>
  <attrib3 xsi:type="xsd:string">Inhalt 3</attrib3>
  <attrib4 xsi:type="xsd:string">Inhalt 4</attrib4>
  <attrib5 xsi:type="xsd:string">Inhalt 5</attrib5>
  </return>
  </ns1:getConfedJoinTreeResponse>
  </SOAP-ENV:Body>

and can be accessed by:
....
var returnObject = soapcall.invoke();
returnObject.getParameters(false, {})[0].attrib3;
returnObject.getParameters(false, {})[0].attrib2.item.value;

Hopefully somebody can tell me how to loop throug the returned array
items or object properties or better; how to get the the returned data
right in a javascript variable.

Thank in advance,

Jan Snelders