dongshou9343 2015-06-18 14:27
浏览 15
已采纳

如何访问此xml字段?

When i var_dump this:

while($row = $updDate->fetch()){//GET FEEDS WHICH UPDATED DATE IS NOT IN DB
        var_dump($this->soccer->GetAllOddsByFixtureMatchId(
        array("fixtureMatch_Id"=>$row['FixtureMatch_Id'])));
        echo $row['FixtureMatch_Id'];}

It returns me this feed.

object(SimpleXMLElement)[11]
public 'OddsList' => 
object(SimpleXMLElement)[12]
  public 'Odds' => 
    array (size=37)
      0 => 
        object(SimpleXMLElement)[13]
          ...
      1 => 
        object(SimpleXMLElement)[14]
          ...
      2 => 
        object(SimpleXMLElement)[15]
          ...
      3 => 
        object(SimpleXMLElement)[16]
          ...
      4 => 
        object(SimpleXMLElement)[17]
          ...
      5 => 
        object(SimpleXMLElement)[18]
          ...
      6 => 
        object(SimpleXMLElement)[19]
          ...
object(SimpleXMLElement)[11]
public 'OddsList' => 
object(SimpleXMLElement)[12]
  public 'Odds' => 
    array (size=37)
      0 => 
        object(SimpleXMLElement)[49]
          ...
      1 => 
        object(SimpleXMLElement)[48]
          ...
      2 => 
        object(SimpleXMLElement)[47]
          ...
      3 => 
        object(SimpleXMLElement)[46]
          ...
      4 => 
        object(SimpleXMLElement)[45]
          ...
      5 => 
        object(SimpleXMLElement)[44]
          ...
      6 => 
        object(SimpleXMLElement)[43]
          ...
object(SimpleXMLElement)[11]
public 'OddsList' => 
object(SimpleXMLElement)[12]
  public 'Odds' => 
    array (size=37)
      0 => 
        object(SimpleXMLElement)[13]
          ...
      1 => 
        object(SimpleXMLElement)[14]
          ...
      2 => 
        object(SimpleXMLElement)[15]
          ...
      3 => 
        object(SimpleXMLElement)[16]
          ...
      4 => 
        object(SimpleXMLElement)[17]
          ...
      5 => 
        object(SimpleXMLElement)[18]
          ...
      6 => 
        object(SimpleXMLElement)[19]
          ...

I want to access Odds object and get some columns from and compare it from columns in my database...

It works good when i use:

->OddsList->Odds

, but i need xpath for some conditions... So i tried to add this ->xpath('/OddsList/Odds')), but it returns me null...

  • 写回答

1条回答 默认 最新

  • douxu9707 2015-06-19 03:15
    关注

    XPath works against XML, so it's hard to tell the exact problem and solution without being able to see the XML. I would guess the problem was due to existence of default namespace. Consider the following sample XML :

    <OddsList xmlns="xmlsoccer.com/">
        <Odd>1</Odd> 
        <Odd>2</Odd> 
    </OddsList>
    

    There is a default namespace pointing to address "xmlsoccer.com" in above XML sample. Note that descendant elements inherit ancestor default namespace implicitly, unless otherwise specified (using explicit namespace prefix, or having local default namespace pointing to different URI). In this case, you need to register mapping of prefix to namespace URI, and use the registered prefix properly in the XPath. For example :

    $string = <<<XML
    <OddsList xmlns="xmlsoccer.com/">
        <Odd>1</Odd> 
        <Odd>2</Odd> 
    </OddsList>
    XML;
    $xml = new SimpleXMLElement($string);
    $xml->registerXPathNamespace("d","xmlsoccer.com/");
    foreach($xml->xpath("/d:OddsList/d:Odd") as $node)
    {
        echo $node ."<br>";
    }
    

    <kbd>Demo</kbd>

    output :

    1
    2
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源