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

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.