Jump to content

Issues grabing data using XMLReader and CURL


livewirerules

Recommended Posts

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?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.