Jump to content

Parsing XML attribute with xpath() // Im too close, Need Help,


jwin27

Recommended Posts

hi, im trying to parse this xml  file : 

xml.gamebookers.com/sport /football.xml_attr.xml

 

i want to echo on my page like this :

 

league name 1

match 1 of league 1

odds odds odds

match 2 of league 1

odds odds odds

.

.

league name 2

match 1 of league 2

odds odds odds

match2 of league 2

odds odds odds

.

.

 

 

this is my code so far

<?php
$xml=simplexml_load_file('http://xml.gamebookers.com/sports/football.xml_attr.xml');

$league=$xml->xpath('//event/..');             // leagues refers to element<group> 
$matches=$xml->xpath('//bettype[@name="Versus (with Draw)"]/..'); // shows matches name (team versus team)
$odds=$xml->xpath('//event/bettype[@name="Versus (with Draw)"]/bet'); //odds of matches 1 x 2


$leaguecount=count($league);
$matchescount=count($matches);
$oddscount=count($odds);

$i=0;

while ($i<$leaguecount){
echo $league[$i]['name'].'<br>';
$i++;
}

echo '<br><br>';

$i=0;
while ($i<$matchescount){
echo $matches[$i]['name'].'<br>';
$i++;
}

$i=0;
while ($i<$oddscount){
echo $odds[$i]['odd'].'<br>';
$i++;
}

?>

 

it prints this:

http://www.mh724.com/school/xp.php

 

so i need something like that:

echo league[$i][mathces[$i][odds[$i]  // like arrays of array but it does not work of course

 

any help will highly appreciated  :shrug:

 

with regardS

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.