Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/09/2009, 06:44
Avatar de neodani
neodani
 
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 17 años, 2 meses
Puntos: 20
Recorrer fichero XML, ¿Cuál es el mejor metodo?

Holas!

Estoy intentando analizar un fichero XML y meter los datos en un array (para luego introducirlos en una bbdd) pero no hay manera!!. Alguien me echa una mano con esto??

Fichero XML

Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Analizar XML</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php

$xmlstr 
= <<<XML
<?xml version="1.0" encoding="utf-8" ?>
<leaguelist><league name="Liga BBVA" leaguelink="https://adserver.itsfogo.com/click.aspx?zoneid=34296&amp;page=betsnew.aspx&amp;LeagueIDs=16108" >
<event  name="Deportivo - Málaga" eventdate="13.09.09 / 17:00" eventlink="https://adserver.itsfogo.com/click.aspx?zoneid=34296&amp;page=betsnew.aspx&amp;EventID=1671799">
<games name="1 X 2">
<result  name="1" odd="1,85" placebetlink="https://adserver.itsfogo.com/click.aspx?zoneid=34296&amp;ResultIDs=53673778&amp;GameIDs=14764329&amp;ResultOdds=1.85&amp;Stake=10"/>
<result  name="X" odd="3,30" placebetlink="https://adserver.itsfogo.com/click.aspx?zoneid=34296&amp;ResultIDs=53673779&amp;GameIDs=14764329&amp;ResultOdds=3.30&amp;Stake=10"/>
<result  name="2" odd="3,75" placebetlink="https://adserver.itsfogo.com/click.aspx?zoneid=34296&amp;ResultIDs=53673780&amp;GameIDs=14764329&amp;ResultOdds=3.75&amp;Stake=10"/>
</games>
</event>
<event  name="Espanyol - R. Madrid" eventdate="13.09.09 / 17:00" eventlink="https://adserver.itsfogo.com/click.aspx?zoneid=34296&amp;page=betsnew.aspx&amp;EventID=1671800">
<games name="1 X 2">
<result  name="1" odd="5,75" placebetlink="https://adserver.itsfogo.com/click.aspx?zoneid=34296&amp;ResultIDs=53673876&amp;GameIDs=14764346&amp;ResultOdds=5.75&amp;Stake=10"/>
<result  name="X" odd="3,55" placebetlink="https://adserver.itsfogo.com/click.aspx?zoneid=34296&amp;ResultIDs=53673877&amp;GameIDs=14764346&amp;ResultOdds=3.55&amp;Stake=10"/>
<result  name="2" odd="1,55" placebetlink="https://adserver.itsfogo.com/click.aspx?zoneid=34296&amp;ResultIDs=53673878&amp;GameIDs=14764346&amp;ResultOdds=1.55&amp;Stake=10"/>
</games>
</event>
</league></leaguelist>
XML;

$xml simplexml_load_string($xmlstr);

foreach(
$xml->league->attributes() as $a => $b) {
    echo 
$a,'="',$b,"<br/>";
}

foreach (
$xml->league as $league) {
    foreach(
$xml->league->event->attributes() as $a => $b) {
        echo 
$a,'="',$b,"<br/>";
        foreach(
$xml->league->event->games->attributes() as $a => $b) {
            echo 
$a,'="',$b,"<br/>";}
    }
}

?>
</body>
</html>
He seguido los consejo de http://www.php-es.com/ref.simplexml.html pero no hay manera.

Muchas gracias de antemano!

Última edición por neodani; 10/09/2009 a las 13:24