1--TEST-- 2XMLReader: libxml2 XML Reader, Move cursor to a named attribute within a namespace, with invalid arguments 3--CREDITS-- 4Mark Baker mark@lange.demon.co.uk at the PHPNW2017 Conference for PHP Testfest 2017 5--SKIPIF-- 6<?php if (!extension_loaded("xmlreader")) print "skip"; ?> 7--FILE-- 8<?php 9// Set up test data in a new file 10$xmlstring = '<?xml version="1.0" encoding="UTF-8"?> 11<books xmlns:ns1="http://www.ns1.namespace.org/" xmlns:ns2="http://www.ns2.namespace.org/"><book ns1:num="1" ns2:idx="2" ns1:idx="3" ns2:isbn="4">book1</book></books>'; 12$filename = __DIR__ . '/015-get-errors.xml'; 13file_put_contents($filename, $xmlstring); 14 15// Load test data into a new XML Reader 16$reader = new XMLReader(); 17if (!$reader->open($filename)) { 18 exit('XML could not be read'); 19} 20 21// Parse the data 22while ($reader->read()) { 23 if ($reader->nodeType != XMLREADER::END_ELEMENT) { 24 // Find the book node 25 if ($reader->nodeType == XMLREADER::ELEMENT && $reader->name == 'book') { 26 $attr = $reader->moveToNextAttribute(); 27 28 // Test for missing namespace argument 29 $attr = $reader->getAttributeNs('idx', null); 30 var_dump($attr); 31 echo $reader->name . ": "; 32 echo $reader->value . "\n"; 33 } 34 } 35} 36 37// clean up 38$reader->close(); 39?> 40===DONE=== 41--CLEAN-- 42<?php 43unlink(__DIR__.'/015-get-errors.xml'); 44?> 45--EXPECTF-- 46Warning: XMLReader::getAttributeNs(): Attribute Name and Namespace URI cannot be empty in %s on line %d 47bool(false) 48ns1:num: 1 49===DONE=== 50