Tema: parsear xml
Ver Mensaje Individual
  #2 (permalink)  
Antiguo 29/04/2011, 19:07
Avatar de Ronruby
Ronruby
 
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: parsear xml

Podrias ir yendo de nodo en nodo pero al final se vera raro en codigo, mejor usa XPath:
Código PHP:
Ver original
  1. <?php
  2.  
  3. $xml = <<<XML
  4. <kml xmlns="http://earth.google.com/kml/2.0">
  5.   <Response>
  6.     <name>1600 amphitheatre mountain view ca</name>
  7.     <Status>
  8.       <code>200</code>
  9.       <request>geocode</request>
  10.     </Status>
  11.     <Placemark>
  12.       <address>
  13.         1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA
  14.       </address>
  15.       <AddressDetails Accuracy="8">
  16.         <Country>
  17.           <CountryNameCode>US</CountryNameCode>
  18.           <AdministrativeArea>
  19.             <AdministrativeAreaName>CA</AdministrativeAreaName>
  20.            <SubAdministrativeArea>
  21.              <SubAdministrativeAreaName>Santa Clara</SubAdministrativeAreaName>
  22.              <Locality>
  23.                <LocalityName>Mountain View</LocalityName>
  24.                <Thoroughfare>
  25.                  <ThoroughfareName>1600 Amphitheatre Pkwy</ThoroughfareName>
  26.                </Thoroughfare>
  27.                <PostalCode>
  28.                  <PostalCodeNumber>94043</PostalCodeNumber>
  29.                </PostalCode>
  30.              </Locality>
  31.            </SubAdministrativeArea>
  32.          </AdministrativeArea>
  33.        </Country>
  34.      </AddressDetails>
  35.      <Point>
  36.        <coordinates>-122.083739,37.423021,0</coordinates>
  37.      </Point>
  38.    </Placemark>
  39.   </Response>
  40. </kml>
  41. XML;
  42.  
  43. $xml = str_replace("xmlns=", "ns=", $xml);
  44. $handle = simplexml_load_string($xml);
  45. var_dump($handle->xpath("//PostalCodeNumber"));
  46.  
  47.  
  48. ?>

Es solo una prueba para que veas como funciona ;)