PHPackages                             stopsopa/sax - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. stopsopa/sax

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

stopsopa/sax
============

Lightweight SAX parser/iterator

v1.1.0(10y ago)0121MITPHPPHP &gt;=5.4.0

Since Feb 6Pushed 2y ago1 watchersCompare

[ Source](https://github.com/stopsopa/stopsopa-sax)[ Packagist](https://packagist.org/packages/stopsopa/sax)[ RSS](/packages/stopsopa-sax/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (1)Versions (6)Used By (0)

[![Build Status](https://camo.githubusercontent.com/5a9ce9fe95be999810be247b2acadf9bff86aec34c87fe657d710bc0052e20cd/68747470733a2f2f7472617669732d63692e6f72672f73746f70736f70612f73746f70736f70612d7361782e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/stopsopa/stopsopa-sax)[![Coverage Status](https://camo.githubusercontent.com/8d3fde49d5ffa1458489a76f287be024b5f41da679503b189572d3b73faebc9b/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f73746f70736f70612f73746f70736f70612d7361782f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/stopsopa/stopsopa-sax?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/e55232c8ea3ea62a2785863c17919913ec4834c0cb348604b0f81dae54404ede/68747470733a2f2f706f7365722e707567782e6f72672f73746f70736f70612f7361782f762f737461626c65)](https://packagist.org/packages/stopsopa/sax)[![License](https://camo.githubusercontent.com/b9f42527aaa3c8d6f76abc257e2f65f8ad2b44b3f2569e26c1281820726b85e8/68747470733a2f2f706f7365722e707567782e6f72672f73746f70736f70612f7361782f6c6963656e7365)](https://packagist.org/packages/stopsopa/sax)

DEPRECATED
==========

[](#deprecated)

Created in 2016 - quite old now and not maintained.

That's was actually fun to implement back then.

stopsopa/sax
============

[](#stopsopasax)

Lightweight SAX parser/iterator

---

Instalation
-----------

[](#instalation)

Follow packagist instructions: [Packagist](https://packagist.org/packages/stopsopa/sax)

Usage of library:
-----------------

[](#usage-of-library)

### In file mode:

[](#in-file-mode)

```
use Stopsopa\Sax\Lib\Sax;

$s = new Sax($path_to_file_witch_xml_or_html, array(
    'mode' => Sax::MODE_FILE
));
// or
$s = new Sax($path_to_file_witch_xml_or_html, Sax::MODE_FILE);

foreach ($s as $d) {
    if ($d['type'] === Sax::N_TAG) {
        // iterates through nodes of xml/html
    }
}

```

### In string mode:

[](#in-string-mode)

```
use Stopsopa\Sax\Lib\Sax;

$s = new Sax($xml_or_html_as_a_string, array(
    'mode' => Sax::MODE_STRING
));
// or
$s = new Sax($xml_or_html_as_a_string, Sax::MODE_STRING);

foreach ($s as $d) {
    if ($d['type'] === Sax::N_TAG) {
        // iterates through nodes of xml/html
    }
}

```

Nodes types:
------------

[](#nodes-types)

### Possible types with their json representation:

[](#possible-types-with-their-json-representation)

- Sax::N\_TAG

---

**node example** **(opening tag)**:

```

```

**data example** **(opening tag)**:

```
{
    "type": 2,
    "raw": "",
    "data": {
        "type": "opening",
        "attr": {
            "id": "eid",
            "class": "red blue",
            "data-at": [
                "one",
                "two",
                null
            ]
        },
        "name": "note"
    },
    "offset": 0
}

```

---

**node example** **(closing tag)**:

```

```

**data example** **(closing tag)**:

```
{
    "type": 2,
    "raw": "",
    "data": {
        "type": "closing",
        "name": "note"
    },
    "offset": 0
}

```

---

**node example** **(empty tag)**:

```

```

**data example** **(empty tag)**:

```
{
    "type": 2,
    "raw": "",
    "data": {
        "type": "empty",
        "attr": {
            "data": "empty"
        },
        "name": "div"
    },
    "offset": 0
}

```

---

- Sax::N\_DATA **(data between xml/html nodes)**

**data example**:

```

value

```

**data example**:

```
{
    "type": 3,
    "raw": "\r\nvalue\r\n",
    "offset": 5
}

```

- Sax::N\_CDATA

**node example**:

```
]]>

```

**data example**:

```
{
    "type": 4,
    "raw": "]]>",
    "data": "test data]>",
    "offset": 5
}

```

- Sax::N\_COMMENT

**data example**:

```

```

**data example**:

```
{
    "type": 5,
    "raw": "",
    "data": " comment ",
    "offset": 0
}

```

- Sax::N\_SPACES **(spaces between xml/html nodes)**

**data example**:

```
{
    "offset": 38,
    "raw": "\\r\\n",
    "type": 1
}

```

### Iteration:

[](#iteration)

```
foreach ($sax_instance as $d) {
    switch ($d['type']) {
        case Sax::N_TAG:
                // do something with decomposed tag
            break;
        case Sax::N_DATA:
                // do something with decomposed data between tag
            break;
        ... etc.
    }
}

```

Additional options:
-------------------

[](#additional-options)

```
$s = new Sax($pathtofile, array(
    'encoding' => 'utf8',
    'chunk' => null, // default 1024
    'mode' => null // default Sax::MODE_FILE, can be also Sax::MODE_STRING
));

```

### License

[](#license)

The MIT License (MIT)
Copyright (c) 2016 Szymon Działowski
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 94.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~19 days

Total

5

Last Release

3673d ago

PHP version history (2 changes)v1.0.1PHP &gt;=5.3.0

v1.0.3PHP &gt;=5.4.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3743506?v=4)[Szymon Dzialowski](/maintainers/stopsopa)[@stopsopa](https://github.com/stopsopa)

---

Top Contributors

[![grytysek](https://avatars.githubusercontent.com/u/875810?v=4)](https://github.com/grytysek "grytysek (68 commits)")[![stopsopa](https://avatars.githubusercontent.com/u/3743506?v=4)](https://github.com/stopsopa "stopsopa (4 commits)")

### Embed Badge

![Health badge](/badges/stopsopa-sax/health.svg)

```
[![Health](https://phpackages.com/badges/stopsopa-sax/health.svg)](https://phpackages.com/packages/stopsopa-sax)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M284](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M345](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
