Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [ROZWIĄZANY] Parsowanie XMLa od googla
Forum PHP.pl > Forum > PHP
Bartess
Witam.
Plik plik.xml zawiera treść jaką otrzymuję pod adresem: https://maps.googleapis.com/maps/api/distan...1382,-3.7914676 i wygląda tak:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <DistanceMatrixResponse>
  3. <status>OK</status>
  4. <origin_address>Two Stiles, Water Ln, Speen, Princes Risborough, Buckinghamshire HP27 0SW, Wielka Brytania</origin_address>
  5. <destination_address>27-29 Penywern Rd, Ystalyfera, Swansea, Neath Port Talbot SA9, Wielka Brytania</destination_address>
  6. <row>
  7. <element>
  8. <status>OK</status>
  9. <duration>
  10. <value>11540</value>
  11. <text>3 godz. 12 min</text>
  12. </duration>
  13. <distance>
  14. <value>296079</value>
  15. <text>296 km</text>
  16. </distance>
  17. </element>
  18. </row>
  19. </DistanceMatrixResponse>
W pliku PHP odczytuję zawartość pliku plik.xml:
  1. <?php
  2. $reader = new XMLReader();
  3. $reader->open('plik.xml');
  4. //$reader->open('https://maps.googleapis.com/maps/api/distancematrix/xml?origins=51.6896118,-0.7846495&destinations=51.7651382,-3.7914676');
  5. while($reader->read()) {
  6. if($reader->nodeType == XMLReader::ELEMENT)
  7. {
  8. $name = $reader->name;
  9. }
  10.  
  11. if($reader->nodeType == XMLReader::TEXT)
  12. {
  13. echo $name.' '.$reader->value.'<br />';
  14. }
  15. }
  16. $reader->close();
  17. ?>
W ten sposób działa dobrze, dostaję to, co potrzebuję.
Jeżeli jednak zamiast
  1. $reader->open('plik.xml');
Ustawię:
  1. $reader->open('https://maps.googleapis.com/maps/api/distancematrix/xml?origins=51.6896118,-0.7846495&destinations=51.7651382,-3.7914676');
To otrzymuję pustą stronę.... W jaki sposób załadować XMLa jako wynik działania skryptu googla?
Pozdrawiam.
Pyton_000
Jak dla mnie to działa. Zobacz logi apache/php
Bartess
Eh...
Miałem nie zainstalowane php5-curl.

Pozdrawiam
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.