php - Split Large XML File Into Smaller Files -
i have ecommerce site needs update products via huge xml file downloaded via ftp distributor.
the products.xml file approx 21mb in size , pulling data , looping through exhaustive single pass.
i need able split original xml file or processed simplexmlelement 1000 products each, load files , process them separately.
i'm pulling xml simplexmlelement casting array looks so:
[1] => array ( [products_name] => product name [products_description] => product description [products_image] => 1234.jpg [products_price] => 9.99 [products_model] => 1234 [item_brandname] => acme inc. [item_upc] => 01234567890 [item_height] => 0.500 [item_length] => 4.250 [item_diameter] => 3.375 [products_weight] => 0.05 [manufacturers_name] => acme distributors [item_vendor_number] => xxx-1234 [products_quantity] => 100 [date_recieved] => 0000-00-00 00:00:00 [prop_packaging] => blister card [product_class] => bat [products_type] => batteries )
how can create individual files of 1000 products in each file , save them?
you can simplexml
functions:
$xml = simplexml_load_file('products.xml'); foreach($xml $id => $product) { $product->asxml($id.'.xml'); }
you can use simplexml_load_string
instead of simplexml_load_file
$xml = simplexml_load_string($products);
note: have simplexmlelement
Comments
Post a Comment