XPath does not work with XMLReader and SimpleXML?

402 views Asked by At

I get feeds from an xml feeder and his XML structure is like this:

<XMLSOCCER.COM>
<OddsList>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Bet-At-Home</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:32.943</UpdatedDate>
  <Type>Over/Under 2.5</Type>
  <HomeOdds>2.22</HomeOdds>
  <AwayOdds>1.58</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Interwetten</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:33.113</UpdatedDate>
  <Type>Over/Under 2.5</Type>
  <HomeOdds>1.85</HomeOdds>
  <AwayOdds>1.75</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>188Bet</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:33.27</UpdatedDate>
  <Type>Over/Under 2.5</Type>
  <HomeOdds>2.11</HomeOdds>
  <AwayOdds>1.8</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Pinnacle</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:32.803</UpdatedDate>
  <Type>Over/Under 2.5</Type>
  <HomeOdds>2.33</HomeOdds>
  <AwayOdds>1.65</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Bet365</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:34.263</UpdatedDate>
  <Type>Handicap</Type>
  <HomeOdds>3.1</HomeOdds>
  <DrawOdds>3.5</DrawOdds>
  <AwayOdds>2</AwayOdds>
  <Handicap>-1</Handicap>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Bet-At-Home</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:34.373</UpdatedDate>
  <Type>Handicap</Type>
  <HomeOdds>1.17</HomeOdds>
  <DrawOdds>5.41</DrawOdds>
  <AwayOdds>10.32</AwayOdds>
  <Handicap>1</Handicap>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Mybet</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:34.5</UpdatedDate>
  <Type>Handicap</Type>
  <HomeOdds>3.35</HomeOdds>
  <DrawOdds>3.5</DrawOdds>
  <AwayOdds>1.85</AwayOdds>
  <Handicap>-1</Handicap>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Expekt</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:33.41</UpdatedDate>
  <Type>Double Chance</Type>
  <HomeOdds>1.15</HomeOdds>
  <DrawOdds>1.85</DrawOdds>
  <AwayOdds>1.3</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Bet-At-Home</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:33.787</UpdatedDate>
  <Type>Double Chance</Type>
  <HomeOdds>1.17</HomeOdds>
  <DrawOdds>1.8</DrawOdds>
  <AwayOdds>1.25</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Mybet</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:34.037</UpdatedDate>
  <Type>Double Chance</Type>
  <HomeOdds>1.15</HomeOdds>
  <DrawOdds>1.85</DrawOdds>
  <AwayOdds>1.25</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>BetClic</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:34.16</UpdatedDate>
  <Type>Double Chance</Type>
  <HomeOdds>1.15</HomeOdds>
  <DrawOdds>1.85</DrawOdds>
  <AwayOdds>1.3</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Unibet</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:33.52</UpdatedDate>
  <Type>Double Chance</Type>
  <HomeOdds>1.22</HomeOdds>
  <DrawOdds>1.84</DrawOdds>
  <AwayOdds>1.29</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>888</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:33.647</UpdatedDate>
  <Type>Double Chance</Type>
  <HomeOdds>1.22</HomeOdds>
  <DrawOdds>1.84</DrawOdds>
  <AwayOdds>1.29</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Pinnacle</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:34.733</UpdatedDate>
  <Type>Asian Handicap</Type>
  <HomeOdds>1.92</HomeOdds>
  <AwayOdds>2</AwayOdds>
  <Handicap>-0.5</Handicap>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>WilliamHill</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:34.623</UpdatedDate>
  <Type>Asian Handicap</Type>
  <HomeOdds>1.36</HomeOdds>
  <AwayOdds>3</AwayOdds>
  <Handicap>0</Handicap>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Betfred</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:34.86</UpdatedDate>
  <Type>Asian Handicap</Type>
  <HomeOdds>1.36</HomeOdds>
  <AwayOdds>3</AwayOdds>
  <Handicap>0</Handicap>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>188Bet</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:34.967</UpdatedDate>
  <Type>Asian Handicap</Type>
  <HomeOdds>1.89</HomeOdds>
  <AwayOdds>2.03</AwayOdds>
  <Handicap>-0.5</Handicap>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Doxxbet</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:31.63</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.85</HomeOdds>
  <DrawOdds>3.3</DrawOdds>
  <AwayOdds>3.92</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>BetSafe</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:30.74</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.84</HomeOdds>
  <DrawOdds>3.25</DrawOdds>
  <AwayOdds>4.25</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Pinnacle</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:30.257</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.92</HomeOdds>
  <DrawOdds>3.4</DrawOdds>
  <AwayOdds>4.8</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>888</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:31.02</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.9</HomeOdds>
  <DrawOdds>3.4</DrawOdds>
  <AwayOdds>4</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Skybet</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:32.177</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.91</HomeOdds>
  <DrawOdds>3.4</DrawOdds>
  <AwayOdds>4</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>WilliamHill</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:29.91</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.91</HomeOdds>
  <DrawOdds>3.3</DrawOdds>
  <AwayOdds>4.33</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Bet365</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:30.02</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.83</HomeOdds>
  <DrawOdds>3.4</DrawOdds>
  <AwayOdds>4.5</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Expekt</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:30.13</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.82</HomeOdds>
  <DrawOdds>3.1</DrawOdds>
  <AwayOdds>4.6</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Betfred</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:30.473</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.83</HomeOdds>
  <DrawOdds>3.3</DrawOdds>
  <AwayOdds>4.33</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Bet-At-Home</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:31.13</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.82</HomeOdds>
  <DrawOdds>3.18</DrawOdds>
  <AwayOdds>4.25</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Interwetten</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:31.397</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.8</HomeOdds>
  <DrawOdds>3.4</DrawOdds>
  <AwayOdds>4</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>BWin</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:31.77</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.85</HomeOdds>
  <DrawOdds>3.3</DrawOdds>
  <AwayOdds>3.9</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Mybet</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:31.943</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.85</HomeOdds>
  <DrawOdds>3.3</DrawOdds>
  <AwayOdds>4</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>BetClic</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:32.067</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.82</HomeOdds>
  <DrawOdds>3.1</DrawOdds>
  <AwayOdds>4.6</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>188Bet</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:32.27</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.86</HomeOdds>
  <DrawOdds>3.15</DrawOdds>
  <AwayOdds>4.05</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>10Bet</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:32.473</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.83</HomeOdds>
  <DrawOdds>3.2</DrawOdds>
  <AwayOdds>4.4</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Sportingbet</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:32.707</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.83</HomeOdds>
  <DrawOdds>3.25</DrawOdds>
  <AwayOdds>4.33</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>NordicBet</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:30.63</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.84</HomeOdds>
  <DrawOdds>3.25</DrawOdds>
  <AwayOdds>4.25</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Ladbrokes</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:30.85</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.85</HomeOdds>
  <DrawOdds>3.1</DrawOdds>
  <AwayOdds>4.25</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>Unibet</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:30.38</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.9</HomeOdds>
  <DrawOdds>3.4</DrawOdds>
  <AwayOdds>4</AwayOdds>
</Odds>
<Odds>
  <FixtureMatch_Id>346076</FixtureMatch_Id>
  <Bookmaker>5Dimes</Bookmaker>
  <UpdatedDate>2015-06-20T19:42:31.507</UpdatedDate>
  <Type>1X2</Type>
  <HomeOdds>1.92</HomeOdds>
  <DrawOdds>3.4</DrawOdds>
  <AwayOdds>4.8</AwayOdds>
</Odds>
</OddsList>

and i try to get all where Bookmaker = Interwetten using this code:

$url = $this->buildUrl($name,$params);   
    $xml = '';

    $reader = new XMLReader();
    $reader->open($url);

    $dom = new DomDocument();
    $pathXML = array();
    while($reader->read() && $reader->nodeType == XMLREADER::ELEMENT && $reader->name == 'XMLSOCCER.COM'){
        $xml = simplexml_import_dom($dom->importNode($reader->expand(),true));

        $pathXML = $xml->xpath('//Odds[contains(Bookmaker,"Interwetten")]');


        /*if($this->getExpression()){
            $xml->xpath($this->getExpression());
        }*/
    }
    //$pls = $xml->xpath('/OddsList/Odds/Bookmaker');

    var_dump($pathXML);

but var_dump retuns me

array (size=0) empty array (size=0) empty array (size=0) empty array (size=0) empty

I need to use XMLReader because that i need to get just conditions from xpath, not whole document...

1

There are 1 answers

4
splash58 On BEST ANSWER

Your while, seems, not executed even once. Code should read, until needed condition will occur

 while($reader->read()) {
   if (reader->nodeType == XMLREADER::ELEMENT && $reader->name == 'XMLSOCCER.COM') ) {
        $xml = simplexml_import_dom($dom->importNode($reader->expand(),true));
        $pathXML = $xml->xpath('//Odds[contains(Bookmaker,"Interwetten")]');
        /*if($this->getExpression()){
            $xml->xpath($this->getExpression());
        }*/
        break;
    }
}