PHP code example of halilim / xml-iterator

1. Go to this page and download the library: Download halilim/xml-iterator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

halilim / xml-iterator example snippets


use XmlIterator\XmlIterator;
$it = new XmlIterator("http://api.example.com/products.xml", "product");

foreach ($it as $k => $v) {
    // Do something with each row ($v), save it to db, echo it, etc. E.g.:
    // echo $k . " => " . var_export($v, true) . "\n\n";
}

0 => array (
  'title' => 'Lorem',
  'brand' => 'ACME',
  'images' =>
  array (
    'image' =>
    array (
      0 => 'http://www.example.com/image1.jpg',
      1 => 'http://www.example.com/image2.jpg',
    ),
  ),
)

1 => array (
  'title' => 'Ipsum',
  'brand' => 'Etc LLC',
  'images' =>
  array (
    'image' =>
    array (
      0 => 'http://www.example.com/image3.jpg',
      1 => 'http://www.example.com/image4.jpg',
    ),
  ),
)