3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $xml = <<<XML <item is-foo="false" is-bar="false"> <item is-bar="true"> <item> <item is-foo="true"> <item /> <item is-foo="true" /> </item> </item> <item is-foo="true" is-bar="true" /> </item> </item> XML; $schema = <<<SCHEMA <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="item"> <xs:complexType> <xs:sequence> <xs:element ref="item" minOccurs="0" maxOccurs="unbounded" /> </xs:sequence> <xs:attribute name="is-foo" type="xs:boolean" default="true" use="optional" /> <xs:attribute name="is-bar" type="xs:boolean" default="false" use="optional" /> </xs:complexType> </xs:element> </xs:schema> SCHEMA; $flags = defined('LIBXML_SCHEMA_CREATE') ? LIBXML_SCHEMA_CREATE : 0; $document = new DOMDocument(); $document->loadXML($xml); var_dump($document->schemaValidateSource($schema, $flags)); $xpath = new DOMXPath($document); foreach ($xpath->query('//item') as $item) { echo $item->getNodePath() . PHP_EOL . ' is-foo : ' . $item->getAttribute('is-foo') . PHP_EOL . ' is-bar : ' . $item->getAttribute('is-bar') . PHP_EOL; }
Output for 5.5.2 - 5.6.28, 7.0.0 - 7.1.0
bool(true) /item is-foo : false is-bar : false /item/item is-foo : true is-bar : true /item/item/item[1] is-foo : true is-bar : false /item/item/item[1]/item is-foo : true is-bar : false /item/item/item[1]/item/item[1] is-foo : true is-bar : false /item/item/item[1]/item/item[2] is-foo : true is-bar : false /item/item/item[2] is-foo : true is-bar : true
Output for 5.2.0 - 5.5.1, hhvm-3.10.0 - 3.12.0
Warning: DOMDocument::schemaValidateSource() expects exactly 1 parameter, 2 given in /in/7cFpS on line 35 NULL /item is-foo : false is-bar : false /item/item is-foo : is-bar : true /item/item/item[1] is-foo : is-bar : /item/item/item[1]/item is-foo : true is-bar : /item/item/item[1]/item/item[1] is-foo : is-bar : /item/item/item[1]/item/item[2] is-foo : true is-bar : /item/item/item[2] is-foo : true is-bar : true
Output for 5.0.0 - 5.1.1, 5.1.3 - 5.1.6
Warning: DOMDocument::schemaValidateSource() expects exactly 1 parameter, 2 given in /in/7cFpS on line 35 NULL Fatal error: Call to undefined method DOMElement::getNodePath() in /in/7cFpS on line 39
Process exited with code 255.
Output for 5.1.2
Warning: DOMDocument::schemaValidateSource() expects exactly 1 parameter, 2 given in /in/7cFpS on line 37 NULL Fatal error: Call to undefined method DOMElement::getNodePath() in /in/7cFpS on line 41
Process exited with code 255.
Output for 4.3.2 - 4.4.1, 4.4.3 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/7cFpS on line 33
Process exited with code 255.
Output for 4.4.2
Fatal error: Cannot instantiate non-existent class: domdocument in /in/7cFpS on line 35
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: domdocument in /in/7cFpS on line 33