verstehe das auslesen einer XML nicht

Kann mir da mal jemand auf die Sprünge helfen. Die XML sieht folgendermassen aus:

<?xml version=„1.0“ encoding=„UTF-8“?>
-<DirectionsResponse>
<status>OK</status>
-<route>
<summary>Staatsstrasse</summary>
-<leg>
+<step>-----
+<step>-----
+<step>-----
+<step>-----
+<step>-----
+<step>-----
+<step>-----
+<step>-----
+<step>-----
+<step>-----
+<step>-----
-<duration>
<value>735</value>
<text>12 Minuten</text>
</duration>

mich interessiert (übungshalber) nur die „12 Minuten“.

So hab ich’s versucht:

	$weg[0] = $api->status->route->summary->attributes()->duration;

bekomme jedoch immer folgende Fehlermeldung:

Notice: Trying to get property of non-object in C:\IP-Symcon\scripts\25893.ips.php on line 15

bin ich da komplett auf dem Holzweg?

bin ich da komplett auf dem Holzweg?

Ja. Wo oder wie, liest Du denn die Datei ein. Ich seh da nix.

Testhalber so.

$api = simplexml_load_string(utf8_encode(file_get_contents("http://maps.google.ch/maps/api/directions/xml?origin=Gunten,Be&destination=Bahnhof,Thun&sensor=false")));

dies entspricht dann dem 1. Post.

$api = simplexml_load_file(utf8_encode("http://maps.google.ch/maps/api/directions/xml?origin=Gunten,Be&destination=Bahnhof,Thun&sensor=false"));
print_r($api);
SimpleXMLElement Object
(
    [status] => OK
    [route] => SimpleXMLElement Object
        (
            [summary] => Staatsstrasse
            [leg] => SimpleXMLElement Object
                (
                    [step] => Array
                        (
                            [0] => SimpleXMLElement Object
                                (
                                    [travel_mode] => DRIVING
                                    [start_location] => SimpleXMLElement Object
                                        (
                                            [lat] => 46.7127600
                                            [lng] => 7.7020300
                                        )

                                    [end_location] => SimpleXMLElement Object
                                        (
                                            [lat] => 46.7203500
                                            [lng] => 7.6855200
                                        )

                                    [polyline] => SimpleXMLElement Object
                                        (
                                            [points] => wqb|Guh_n@?DAVCz@CRIdAIt@SfAQn@IT]pAk@~Bc@fBYlAa@jA_@dA_@fAQx@G^E\?^?j@?DBl@HvAAL?l@Eh@I`@Md@]z@e@z@_@l@y@|Ai@hAk@pAw@fB_@fAOn@Kv@I`AEn@G~@Gj@Ir@Ef@Ch@A^CXCTEZMr@Of@[l@MNc@j@mA|@uAbAy@h@eGdEgClA
                                        )

                                    [duration] => SimpleXMLElement Object
                                        (

hier siehst wo Du hin willst.

print_r($api->route->leg->step->duration->text);

tausend Dank Rainer :slight_smile: