Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Issues grabing data using XMLReader and CURL

$
0
0

I have a feed that contains over 10000 vehicles and is about 300 mb and trying to grab and display the name and the price of each vehicle.The problem is it displays all the data in the feed.

Below is the feed that i used

 

 

 <vehicle>
      <type>Double Cab </type>
      <price>19.5k</price>
      <model>GTX</model>
<descrip>sdsadasdasdsa</descrip>
    </vehicle>

 <vehicle>
      <type>Cruise </type>
      <price>78k</price>
      <model>Ultra</model>
     <descrip>sdsadasdasdsa</descrip>
    </vehicle>

 <vehicle>
      <type>Jeep/ Wagon </type>
      <price>2k</price>
      <model>Body Kit</model>
      <descrip>sdsadasdasdsa</descrip>
    </vehicle>
 

 

I’m using the below code.

 

 

$url = 'vcfeed.php';

$xname ="test";
$xPassword ="testuser";

$post_data = array("username" => $xname, "password" => $xPassword");
$ch = curl_init($url);

$c[CURLOPT_POST] = true;
$c[CURLOPT_POSTFIELDS] = $post_data;

foreach($c as $k=>$v){$c[$k] = $v;}
curl_setopt_array($ch,$c);

$xml = curl_exec($ch);

curl_close($ch);

$z = new XMLReader;
$z->open($xml);

$doc = new DOMDocument;


while ($z->read() && $z->name !== 'vehicle');


while ($z->name === 'vehicle')
{

    $node = simplexml_import_dom($doc->importNode($z->expand(), true));


  echo $node->model;
  echo $node->price;


    $z->next('vehicle');
}

 

 

 

Although i have used  

 

echo $node->model;
  echo $node->price;
 

 

It doesn’t show those 2 values for each result. Can someone tell me what am i doing wrong here?

 


Viewing all articles
Browse latest Browse all 13200

Trending Articles