xref: /PHP-7.4/ext/xmlreader/tests/004.phpt (revision 26dfce7f)
1--TEST--
2XMLReader: libxml2 XML Reader, attributes test
3--SKIPIF--
4<?php if (!extension_loaded("xmlreader")) print "skip"; ?>
5--FILE--
6<?php
7$filename = __DIR__ . '/_004.xml';
8
9$xmlstring = '<?xml version="1.0" encoding="UTF-8"?>
10<books><book num="1" idx="2">book1</book></books>';
11file_put_contents($filename, $xmlstring);
12
13$reader = new XMLReader();
14if (!$reader->open($filename)) {
15	exit();
16}
17
18while ($reader->read()) {
19	if ($reader->nodeType != XMLREADER::END_ELEMENT) {
20		echo $reader->name."\n";
21		if ($reader->nodeType == XMLREADER::ELEMENT && $reader->hasAttributes) {
22			$attr = $reader->moveToFirstAttribute();
23			while ($attr) {
24				echo "   Attribute Name: ".$reader->name."\n";
25				echo "   Attribute Value: ".$reader->value."\n";
26				$attr = $reader->moveToNextAttribute();
27			}
28		}
29	}
30}
31$reader->close();
32unlink($filename);
33?>
34===DONE===
35--EXPECT--
36books
37book
38   Attribute Name: num
39   Attribute Value: 1
40   Attribute Name: idx
41   Attribute Value: 2
42#text
43===DONE===
44