Hi,
There is this link -> http://data.giub.uni-bonn.de/openrouteservice/php/DetermineRoute_rajan.php?Start=7.0892567,50.7265543&Via=&End=7.0986258,50.7323634&lang=en&distunit=YD&routepref=Fastest&avoidAreas=&useTMC=false&noMotorways=false&noTollways=false&instructions=true !

where I need to extract text, perhaps ->

<xls:Instruction>Drive half left on Kaiserstraße</xls:Instruction>
<xls:distance value="284" uom="YD"/> (bold text).

On using something like this :

$url="url_just_shown_above";
 $output = file_get_contents($url);
 $xml = simplexml_load_string($output);
 echo $xml->xls:RouteInstruction->xls:Instruction."<br />";

I am getting error ->
Parse error: syntax error, unexpected ':', expecting ',' or ';' in C:\Program Files\ms4w\Apache\htdocs\ors\try.php on line 9

Please guide,so that I can extract Routing information and within xls:Instruction and distance with attribute value="284" throughout whole xml file.

Any kind of help will be deeply appreciated. Thanks a lot !!

Do a var_dump($xml); to see its structure:

To use property names that have characters not allowed in PHP you have to quote them, and encapsulate the string in braces.

eg:

echo $xml->{'xls:RouteInstruction'}->{'xls:Instruction'}."<br />";

Do a var_dump($xml); to see its structure:

To use property names that have characters not allowed in PHP you have to quote them, and encapsulate the string in braces.

eg:

echo $xml->{'xls:RouteInstruction'}->{'xls:Instruction'}."<br />";

You could also cast the object to an array, it that is simpler.

$xml = (array) simplexml_load_string($output);
 echo $xml['xls:RouteInstruction']['xls:Instruction']."<br />";

That should do the same, with less syntax.

Hi,Thanks for great help.The error no longer exists. But,I don't know why?, due to nature of file or whatever, I am not able to retrieve data from XML file. :(

I want to extract bold text of them from the url/xml file:
<xls:Instruction>Drive half left on Kaiserstraße</xls:Instruction>
<xls:distance value="284" uom="YD"/> (here an attribute).
From the second code snippet you provided, it gives :->
array(1) { ["@attributes"]=> array(1) { ["version"]=> string(3) "1.1" } } as the value for var_dump and shows NULL !

To calculate attribute for distance: I used this ->

$xml = simplexml_load_file("http://data.giub.uni-bonn.de/openrouteservice/php/DetermineRoute_rajan.php?Start=7.0892567,50.7265543&Via=&End=7.0986258,50.7323634&lang=en&distunit=YD&routepref=Fastest&avoidAreas=&useTMC=false&noMotorways=false&noTollways=false&instructions=true");

foreach($xml->{'xls:distance[5]'}->attributes() as $a => $b)
  {
  echo $a,'="',$b,"\"</br>";
  }

Please help me with extracting above shown bold text of it,will deeply appreciate that..Thanks again !

Hi,Thanks for great help.The error no longer exists. But,I don't know why?, due to nature of file or whatever, I am not able to retrieve data from XML file. :(

I want to extract bold text of them from the url/xml file:
<xls:Instruction>Drive half left on Kaiserstraße</xls:Instruction>
<xls:distance value="284" uom="YD"/> (here an attribute).
From the second code snippet you provided, it gives :->
array(1) { ["@attributes"]=> array(1) { ["version"]=> string(3) "1.1" } } as the value for var_dump and shows NULL !

To calculate attribute for distance: I used this ->

$xml = simplexml_load_file("http://data.giub.uni-bonn.de/openrouteservice/php/DetermineRoute_rajan.php?Start=7.0892567,50.7265543&Via=&End=7.0986258,50.7323634&lang=en&distunit=YD&routepref=Fastest&avoidAreas=&useTMC=false&noMotorways=false&noTollways=false&instructions=true");

foreach($xml->{'xls:distance[5]'}->attributes() as $a => $b)
  {
  echo $a,'="',$b,"\"</br>";
  }

Please help me with extracting above shown bold text of it,will deeply appreciate that..Thanks again !

$xml->{'xls:distance[5]'}->attributes()

should look more like:

$xml->{'xls:distance'}[5]->attributes()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.