标题xml中使用php的空间

时间:2015-03-09 19:08:50

标签: php xml

我拥有它

<match>
      <Bet OddsType="01">
        <Odds OutCome="1">9.0</Odds>
        <Odds OutCome="x">8.5</Odds>
        <Odds OutCome="2">6.75</Odds>
      </Bet>
      <Bet OddsType="02">
        <Odds OutCome="1">2.0</Odds>
        <Odds OutCome="2">3.5</Odds>        
      </Bet>
....

</match>

所以在php中我通过$xml = simplexml_load_file(调用网页然后我尝试获取

foreach($xml->Match->Bet as $Bet){

$Bet->Odds[0]//for first time it give me 9.0, for second 2.0..etc

这里我没有问题,但我需要获得OutCome的价值,但是当我为$ Bet做print_r时,我得到Array ( [OddsType] => 02 ) [Odds] => Array ( [0] => 9.0 [1] => 8.5 [2] =>6.75))....而OutCome消失了

我需要帮助才能获得OutCome的价值。

1 个答案:

答案 0 :(得分:1)

您可以使用attributes()访问OutCome属性。例如:

foreach($xml->Match->Bet as $Bet){

   $attr = $Bet->Odds[0]->attributes();
   var_dump($attr['OutCome']);
}