2010年1月20日星期三

[fw-webservices] Retrieving Attributes

Hello Guys,

I am new to Zend Framework and I am trying to make a rest client library for
one of our APIs'.

My question is how do we retrieve attribute values from an xml response
through Zend.

Code looks like this

$client = new
Zend_Rest_Client('http://*******/listDatastreams/vapp:2?xml=true');
$result = $client->get();

Response XML for the url is like this

<?xml version="1.0" encoding="UTF-8"?>
<objectDatastreams pid="vapp:2" baseURL="http://******/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.fedora.info/definitions/1/0/access/
http://www.fedora.info/definitions/1/0/listDatastreams.xsd">
<datastream dsid="DC" label="Dublin Core Record for this object"
mimeType="text/xml" />
<datastream dsid="OVA" label="xxx.jpg" mimeType="application/octet-stream"
/>
</objectDatastreams>

As you guys notice I don't have any values for tags here but the stuff I
need is in the attributes itself.

The Zend Response looks like this

Zend_Rest_Client_Result Object
(
[_sxml:protected] => SimpleXMLElement Object
(
[@attributes] => Array
(
[pid] => vapp:2
[baseURL] => *******
)

[datastream] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[dsid] => DC
[label] => Dublin Core Record for this
object
[mimeType] => text/xml
)

)

[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[dsid] => **
[label] => ****.jpg
[mimeType] => application/octet-stream
)

)

)

)

)

Now my question is how can I iterate over this data structure and retrieve
the information in an associative array like this (Something of this kind)

[datastream] => Array(
[0] => Array
(
[dsid] => DC
[label] => Dublin Core Record for this
object
[mimeType] => text/xml
)

)

I know how to do it with simpleXML or php directly and I dont need any
guidance with that. My question is can this be achieved with the framework.


Also like to make an authenticated Rest request. How do I do that?

Currently I simply do $client = new Zend_Rest_Client('****');

But where can I insert my auth data?

I would sincerely appreciate and responses and directions from you.


Thanks,
Vamsee

--
View this message in context: http://n4.nabble.com/Retrieving-Attributes-tp1018746p1018746.html
Sent from the Zend Web Services mailing list archive at Nabble.com.

没有评论: