zendframework / zendxml
Utility library for XML usage, best practices, and security in PHP
Installs: 8 706 912
Dependents: 34
Suggesters: 1
Security: 1
Stars: 29
Watchers: 15
Forks: 15
Open Issues: 0
Requires
- php: ^5.6 || ^7.0
Requires (Dev)
- phpunit/phpunit: ^5.7.27 || ^6.5.8 || ^7.1.4
- zendframework/zend-coding-standard: ~1.0.0
This package is auto-updated.
Last update: 2020-01-20 20:25:45 UTC
README
Repository abandoned 2019-12-31
This repository has moved to laminas/laminas-xml.
An utility component for XML usage and best practices in PHP
Installation
You can install using:
curl -s https://getcomposer.org/installer | php
php composer.phar install
Notice that this library doesn't have any external dependencies, the usage of composer is for autoloading and standard purpose.
ZendXml\Security
This is a security component to prevent XML eXternal Entity (XXE) and XML Entity Expansion (XEE) attacks on XML documents.
The XXE attack is prevented disabling the load of external entities in the libxml library used by PHP, using the function libxml_disable_entity_loader.
The XEE attack is prevented looking inside the XML document for ENTITY usage. If the XML document uses ENTITY the library throw an Exception.
We have two static methods to scan and load XML document from a string (scan) and from a file (scanFile). You can decide to get a SimpleXMLElement or DOMDocument as result, using the following use cases:
use ZendXml\Security as XmlSecurity; $xml = <<<XML <?xml version="1.0"?> <results> <result>test</result> </results> XML; // SimpleXML use case $simplexml = XmlSecurity::scan($xml); printf ("SimpleXMLElement: %s\n", ($simplexml instanceof \SimpleXMLElement) ? 'yes' : 'no'); // DOMDocument use case $dom = new \DOMDocument('1.0'); $dom = XmlSecurity::scan($xml, $dom); printf ("DOMDocument: %s\n", ($dom instanceof \DOMDocument) ? 'yes' : 'no');