2017 © Pedro Peláez
 

library xml-iterator

XML Reader to simplexml/array iterator with low memory usage and an acceptable level of ease of use.

image

halilim/xml-iterator

XML Reader to simplexml/array iterator with low memory usage and an acceptable level of ease of use.

  • Friday, August 11, 2017
  • by halil
  • Repository
  • 3 Watchers
  • 16 Stars
  • 33,612 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 8 Forks
  • 0 Open issues
  • 3 Versions
  • 10 % Grown

The README.md

xml-iterator

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-scrutinizer] Quality Score ![Total Downloads][ico-downloads], (*1)

XML Reader to array/object iterator with low memory usage (basically a Space–time tradeoff) and an acceptable level of ease of use. Mostly useful for importing sequential data from external API's., (*2)

Installation (Composer)

$ composer require "halilim/xml-iterator"

Usage

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";
}

Note: When working with remote files it's advised to copy the file to a temporary local location first. Otherwise if the import takes a long time, "extra content at the end of the document" kind of errors may occur (or at least this was what happened to me)., (*3)

Example input:, (*4)

<?xml version="1.0" encoding="UTF-8"?>
<products>
    <product>
        <title>Lorem</title>
        <brand>ACME</brand>
        <images>
            <image>http://www.example.com/image1.jpg</image>
            <image>http://www.example.com/image2.jpg</image>
        </images>
    </product>
    <product>
        <title>Ipsum</title>
        <brand>Etc LLC</brand>
        <images>
            <image>http://www.example.com/image3.jpg</image>
            <image>http://www.example.com/image4.jpg</image>
        </images>
    </product>
</products>

Example output:, (*5)

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',
    ),
  ),
)

Testing

bash $ composer test, (*6)

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details., (*7)

List of Contributors

We thank all our contributors for their contributions., (*8)

License

The MIT License (MIT). Please see License File for more information., (*9)

The Versions

11/08 2017

dev-master

9999999-dev

XML Reader to simplexml/array iterator with low memory usage and an acceptable level of ease of use.

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-dom *
  • ext-simplexml *
  • ext-spl *
  • ext-xmlreader *

 

The Development Requires

xml iterator xmlreader simplexml

11/08 2017

1.0.1

1.0.1.0

XML Reader to simplexml/array iterator with low memory usage and an acceptable level of ease of use.

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-dom *
  • ext-simplexml *
  • ext-spl *
  • ext-xmlreader *

 

The Development Requires

xml iterator xmlreader simplexml

30/11 2014

1.0.0

1.0.0.0

XML Reader to simplexml/array iterator with low memory usage and an acceptable level of ease of use.

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-dom *
  • ext-simplexml *
  • ext-spl *
  • ext-xmlreader *

 

xml iterator xmlreader simplexml