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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

jan-80
I'm trying to parse/access an associative/hashed array from a soap
server. I can't find a way to retrieve/access/parse the returned
associative
array in Firefox 2.0 using JavaScript

after my call to the server...
var returnObject = soapcall.invoke();

the returned value (returnObject.getParameters(false, {})[0].value)
appears to be a SOAPPropertyBag but I can't find a way to get this
into a javascript associative array/object.

returnObject.getParameters(false, {})[0].element is a reference to the
returned soap xml responce. But the idea of using soap or any other
rpc method is that you don't have to walk the DOM tree yourself.

Any help is greatly appreciated,

Thank in advance

Jan Snelders

_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

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

jan-80
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

_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

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

mozilla.org
[hidden email] wrote:
> Hopefully somebody can tell me how to loop throug the returned array
> items or object properties

Given that you're using an rpc-style of exchange, you'll hopefully
find a way to get at the associative array using the built-in decoding.

But as a last resort you can always use xpath to grab what you need
out of the soap xml response - something like the code below.

Cheers -

Leni.

var doc = soapresponse.message;

var query =
"/soap:Envelope/soap:Body/ns1:getConfedJoinTreeResponse/ns1:return/ns1:item";

var resultType = XPathResult.ORDERED_NODE_ITERATOR_TYPE;

var nsResolver = null;
// you probably need a better nsResolver function, see:
// http://developer.mozilla.org/en/docs/DOM:document.evaluate

var result = doc.evaluate(query, doc, nsResolver, resultType, null);

try {
   var node = result.iterateNext();

   while (node)
   {
     // each <item> node has a <key> and <value> child
     // you can populate an associative array here
   }
   catch(e) {
     dump("exception:" + e);
   }
}

_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml