Hello,
I have to parse an xml document that contains names of sports teams , but these sport teams tags are included in league tags , so inside a league can be a variable number of teams (1, 2 etc.). Like this :

<league>
<name>NCAA</name>
<team>
<name>Akron </name>
<decimalodds>2</decimalodds>
</team>
<team>
<name>Ohio </name>
<decimalodds>1.833333</decimalodds>
</team>
</league>
<league>
<name>AFC</name>
<team>
<name>Indianapolis Colts</name>
<decimalodds>1.0625</decimalodds>
</team>
<team>
<name>Jacksonville Jaguars</name>
<decimalodds>11</decimalodds>
</team>
<team>
<name>Tennessee Titans</name>
<decimalodds>11</decimalodds>
</team>
</league>
.............

So first league has 2 teams inside (2 children) and second has 3 teams , but the number of leagues can also be variable from one xml file to another.

I need to get directly name of teams using xpath and put it in array but also get the league for each team , which , in terms of xpath , means the parent of each children, like this :

$feed = array( 'team_name' => '../league/team/name'
'league_name' => '//team/../name ',

};

So , my array should have:


$feed [0]= 'Akron'
$feed [0]= 'NCAA'

$feed [1]= 'Ohio'
$feed[1]= 'NCAA'

$feed [2]= 'Indianapolis Colts'
$feed[2]= 'AFC'

$feed [3]= 'Jacksonville Jaguars'
$feed[3]= 'AFC'

$feed [4]= 'Tennessee Titans'
$feed[4]= 'AFC'

but I don't !!
Instead i have :

$feed [0]= 'Akron'
$feed [0]= 'NCAA'

$feed [1]= 'Ohio'
$feed[1]= 'AFC'

$feed [2]= 'Indianapolis Colts'
$feed[2]= ''

$feed [3]= 'Jacksonville Jaguars'
$feed[3]= ''

$feed [4]= 'Tennessee Titans'
$feed[4]= ''


So what can I do ? Is there any solution to make xpath corelate children witj parents and treat them separately ??

Thank you.

Hello,

So what can I do ? Is there any solution to make xpath corelate children witj parents and treat them separately ??

.

I meant not treat them separately.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.