Jump to content

Problem reading xml attributes with php xpath function


jwin27

Recommended Posts

<league name="italy" id="1">

    <match name="AC Milan v Palermo" time="15/02/2011 20:45">

          <bettype name="Versus (with Draw)">

      <bet outcome_name="AC Milan"      odd="1.87">

              <bet outcome_name="X"                odd="3.40">

              <bet outcome_name="Palermo"  odd="4.00">

          </bettype>

    </match>

 

    <match name="Juventus v Torino"  time="15/02/2011 20:45">

        <bettype name="Versus (with Draw)">

            <bet outcome_name="Juventus"  odd="2.00">

              <bet outcome_name="X"          odd="3.00">

              <bet outcome_name="Torino"  odd="2.00">

        </bettype>

<bettype name="Half Time">

              <bet outcome_name="1"  odd="2.40">

              <bet outcome_name="X"  odd="3.40">

              <bet outcome_name="2"  odd="1.40">

          </bettype>

    </match>

</league>

 

<league name="Spain" id="2">

    <match name="Barcelona v Real Madrid" time="15/03/2011 21:45">

          <bettype name="Versus (with Draw)">

      <bet outcome_name="Barcelona"    odd="1.87">

              <bet outcome_name="X"            odd="3.40">

              <bet outcome_name="Real Madrid"  odd="4.00">

        </bettype>

    </match>

</league>

 

 

im trying to parse attributes of above xml  with using xpath functions. what i want to output is this:

(  <bettype name="Half Time"> this will be ignored  )

 

Italy

AC Milan v Palermo

1.87 3.40 4.00

Juventus v Torino

2.00 3.00 2.00

 

spain

Barcelona v Real Madrid

1.87 3.40 4.00

 

 

im trying do this with below xpath codes

 


$xml=simplexml_load_file('http://xml.gamebookers.com/sports/football.xml_attr.xml');
$league=$xml->xpath("//league");          
$matches=$xml->xpath('//bettype[@name="Versus (with Draw)"]/..'); 
$odds=$xml->xpath('//match/bettype[@name="Versus (with Draw)"]/bet'); 

 

i searched and tried lots of tutorials. i need help in writing the correct code :(

thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.