lightools/xml
Simple and safe parsing of XML and HTML sources.
Maintainers
v3.0.0
2021-08-18 11:36 UTC
Requires
- php: >=8.0
- ext-dom: *
- ext-libxml: *
Requires (Dev)
- editorconfig-checker/editorconfig-checker: ^10.2
- nette/tester: 2.*
- phpstan/phpstan: ^0.12.94
- phpstan/phpstan-strict-rules: ^0.12.10
- slevomat/coding-standard: ^7.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
MIT d0dde5614cc32b8b878196916ec52ac452bfae58
This package is auto-updated.
Last update: 2026-06-04 14:16:37 UTC
README
This library provides simple interface for loading XML or HTML strings to DomDocument object. It prevents some known vulnerabilities and allows you to handle LibXML errors simply by catching XmlException as you can see below.
Installation
$ composer require lightools/xml
Simple usage
Both loading methods (loadXml and loadHtml) return DomDocument. If you prefer working with SimpleXmlElement, you can use simplexml_import_dom function.
$xml = '<?xml version="1.0"?><root>text</root>'; $html = '<!doctype html><title>Foo</title>'; $loader = new Lightools\Xml\XmlLoader(); try { $xmlDomDocument = $loader->loadXml($xml); $htmlDomDocument = $loader->loadHtml($html); } catch (Lightools\Xml\XmlException $e) { // process exception }
How to run checks
$ composer check
Versions
- v1.x is for PHP 5.4 and higher
- v2.x is for PHP 7.1 and higher
- v3.x is for PHP 8.0 and higher
