Search by

jkphl / dom-factory

jkphl

Simple HTML5/XML DOM factory

Package info

github.com/jkphl/dom-factory

pkg:composer/jkphl/dom-factory

Statistics

Installs: 198 616

Dependents: 6

Suggesters: 0

Stars: 1

Open Issues: 1

v2.0.0 2026-11-13 15:26 UTC

This package is auto-updated.

Last update: 2026-11-13 15:27:02 UTC


README

CI Clear architecture

Simple HTML5/XML DOM factory

dom-factory creates regular PHP DOMDocument objects from web documents (HTML5, SVG, XML, etc.) — from strings, files or URIs. Compared to PHP's default DOMDocument creation, it supports

  • HTML5 elements (e.g. <main>, <header>, <footer>, etc.),
  • inlined foreign formats (e.g. SVG and MathML),
  • XML style namespaces and
  • automatic character encoding detection (byte order mark, HTTP header, XML declaration and <meta> element).
use Jkphl\Domfactory\Ports\Dom;

$dom = Dom::createFromString('<!DOCTYPE html><html><body><main>…</main></body></html>');
$dom = Dom::createFromFile('/path/to/file.html');
$dom = Dom::createFromUri('https://example.com/path/to/file.xml');

Documentation

Please find the project documentation in the doc directory.

Installation

This library requires PHP 8.2 or later with the dom, libxml and mbstring extensions. I recommend using the latest available version of PHP as a matter of principle. It's installable and autoloadable via Composer as jkphl/dom-factory.

composer require jkphl/dom-factory

Supported versions

Version PHP Guzzle
2.x 8.2 – 8.5 7.x and 8.x
1.x 7.2.5 – 8.5 7.x and 8.x

Upgrading from 1.x

Version 2.0 raises the minimum PHP version to 8.2 and adds native type declarations. The public API (Dom::createFromString(), Dom::createFromFile() and Dom::createFromUri()) is unchanged apart from the stricter parameter and return types. Please see the changelog for the details, especially if you implement HtmlParserInterface or extend one of the library classes.

Quality

To run the unit tests, the coding standard check and the static analysis at the command line, issue composer install and then composer test at the package root. The individual checks are available as composer phpunit, composer check-style and composer phpstan.

This library attempts to comply with PSR-1, PSR-12, and PSR-4. If you notice compliance oversights, please send a patch via pull request.

Contributing

Found a bug or have a feature request? Please have a look at the known issues first and open a new issue if necessary. Please see contributing and conduct for details.

Security

If you discover any security related issues, please email joschi@kuphal.net instead of using the issue tracker.

Credits

License

Copyright © 2020 Joschi Kuphal / joschi@kuphal.net. Licensed under the terms of the MIT license.