How to access to this xml field?

88 Views Asked by At

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

There are 1 best solutions below

2
On BEST ANSWER

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>";
}

Demo

output :

1
2