Insert only selection from XML datafeed

Hello Guys

I’ve been working with XML datafeeds and I have a feed that holds 3,000 products.

However, I only want to use products from the feed with ‘dahon’ in the name. This is only about 12 of the 3,000.

Can I modify my PHP to only insert the products with ‘dahon’ in the name?

Here’s my code I’m using…

$xml = simplexml_load_file("foldingdatafeed_79329.xml");

foreach($xml->merchant->prod as $product){
$productid = $product->id;
$name = $product->text->name;
$descrip = $product->text->desc;

$sql = "INSERT INTO products (productid, productname, productdescription)
VALUES ('$productid', '$name', '$descrip')";

Any help would be appreciated

The easiest way to do this would be to use an IF statement and the preg_match function, see the below example:

if (preg_match('/dahon/i', $product->text->name)) {
    // Insert into database

Lets say you wanted to use *nix text tools to pull out those 12 records from the original xml file to a second, smaller file - how could it be done, anyone know?

Maybe its not strictly a reply, just a musing on the same subject.