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