PHPackages                             kalle/xml - 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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. kalle/xml

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

kalle/xml
=========

Compact XML library for PHP with immutable and streaming writers, tree and streaming readers, reader queries, canonicalization, DOM interop, import, and XSD validation

0.1.0(3mo ago)010MITPHPPHP ^8.2CI passing

Since Apr 19Pushed 3mo agoCompare

[ Source](https://github.com/kalicki2k/xml)[ Packagist](https://packagist.org/packages/kalle/xml)[ RSS](/packages/kalle-xml/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

kalle/xml
=========

[](#kallexml)

`kalle/xml` is a compact, strict XML library for PHP 8.2+.

`XmlBuilder` builds immutable XML models. `XmlWriter` serializes complete `XmlDocument` values. `StreamingXmlWriter` is the separate imperative writer for incremental output to file and stream targets.

It provides:

- `XmlBuilder` for immutable, tree-based XML construction
- `XmlWriter` for serializing built documents to strings, files, or streams
- `StreamingXmlWriter` for incremental XML output to files and streams
- `StreamingXmlReader` for incremental, cursor-based XML reading, subtree extraction, and non-overlapping record iteration via `readElements()`
- `XmlReader` for read-only traversal of existing XML
- `XmlCanonicalizer` for deterministic canonical XML output across writer, reader, import, and DOM flows
- `XmlDomBridge` plus DOM entry points on `XmlReader` for explicit DOM interop
- `findAll()` and `findFirst()` for small namespace-aware element queries on the reader model
- `XmlImporter` for importing reader results back into the writer model
- `XmlValidator` for validating XML against XSD schemas

The package stays intentionally narrow in scope. It covers XML writing, streaming XML reading, read-only tree loading, small reader-side queries, deterministic canonicalization, explicit DOM interop, reader-to-writer import, and XSD validation without trying to replace DOM, wrap all of XPath, or become a broad XML framework.

Installation
------------

[](#installation)

```
composer require kalle/xml
```

Runtime requirements: `ext-dom`, `ext-libxml`, and `ext-xmlreader`.

Current Scope
-------------

[](#current-scope)

Included:

- tree-based XML building with `XmlBuilder`
- document serialization with `XmlWriter::toString()`, `toFile()`, and `toStream()`
- streaming XML writing with `StreamingXmlWriter`
- streaming XML reading and non-overlapping record iteration with `StreamingXmlReader`
- read-only XML loading with `XmlReader`
- canonical XML output with `XmlCanonicalizer`
- explicit DOM interop with `XmlDomBridge` and `XmlReader::fromDomDocument()` / `fromDomElement()`
- small namespace-aware element queries with `findAll()` and `findFirst()`
- reader-to-writer import with `XmlImporter`
- compact XSD validation with `XmlValidator`

Out of scope:

- mutation APIs for loaded XML
- broad DOM or XPath wrapper APIs
- XML-to-array or XML-to-object mapping
- XML diff, patch, merge, or signature tooling
- broad schema-framework features beyond compact XSD validation

Quick Example
-------------

[](#quick-example)

```
