Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Cant get nested xml values via restful service' getValues


Go to End


1268 Views

Avatar
theoldlr

Community Member, 103 Posts

10 February 2011 at 7:16am

This section will properly get the xml response

$directions = new RestfulService("http://maps.googleapis.com/maps/api/directions/xml");
        $params = array(
            'origin' => $data["Start"],
            'destination' => $this->Address,
            'sensor' => 'false'    
        );
        
        $directions->setQueryString($params);
        $xmlResponse=$directions->request()->getBody();

Here is where the trouble comes in:

$node='/DirectionsResponse/route/leg/step/';         
$HTMLStepsObjects=$directions->getValues($xmlResponse,$node, "html_instructions");

//using searchValue as below works fine, but only gets 1 result, not all of them
//$steps=$directions->searchValue($xmlResponse,$node.'html_instructions');


 return $HTMLStepsObjects->Count();

This will always return that there are 0 in the DataObjectSet, which means its not working right. Per the RestfulService API: When you get to the depth in the hierachchy use node_child_subchild syntax to get the value.
I have tried this in many combinations:
$node='DirectionsResponse_route_leg_step';
$node='DirectionsResponse_route_leg_step_';
$node='_DirectionsResponse_route_leg_step_';
$node='_DirectionsResponse/route/leg/step';
$node='/DirectionsResponse/route/leg/step';
$node='/DirectionsResponse/route/leg/step/';
$node='DirectionsResponse/route/leg/step/';
$node='DirectionsResponse/route/leg/step';
(I tried slashes because it worked for searchValue() ).

Would really appreciate any advice! TIA!