An open API service indexing awesome lists of open source software.

https://github.com/alex-oleshkevich/php-fast-xml-parser

Fast SAX XML parser for PHP.
https://github.com/alex-oleshkevich/php-fast-xml-parser

parsing php sax sax-parser xml

Last synced: 3 months ago
JSON representation

Fast SAX XML parser for PHP.

Awesome Lists containing this project

README

        

PHP Fast XML Parser
=========

PHP Fast XML Parser is a PHP library for parsing large XML files using PHP.
Key features:

- Lightweight;
- Flexible (result can be easily managed via callback handlers);
- Good for memory critical projects (~10Mb in average while parsing 500mb XML file)

[![Build Status](https://travis-ci.org/alex-oleshkevich/php-fast-xml-parser.svg)](https://travis-ci.org/alex-oleshkevich/php-fast-xml-parser)

## Installation

```
composer require alex.oleshkevich/fast-xml-parser
```

Example & Tutorial
--------------

```php
setOnItemParsedCallback(function ($item) use ($self) {
// do smth with parsed item
});

// set "on progress" callback
$handler->setOnProgressCallback(function ($bytesProcessed, $bytesTotal) use ($self) {
// eg. draw a progress bar
});

// instantiate
$parser = new Parser($handler);

// define tags which you don't want to include in resulting array (optional)
$parser->setIgnoreTags(['root']);

// define end tag for every item
// (this is used as marker to determine when XML
// item was processed.
// For example, if you want to extract "value" from this XML source
//
// VALUE
// VALUE
// VALUE
//
// you must call $parser->setEndTag('value') so library can
// emit content of every tag in "onItemParsed" event.
$parser->setEndTag('value');

// run
$parser->parse('bigfile.xml');
```