xref: /PHP-8.2/ext/xmlreader/tests/004.phpt (revision 74859783)
1--TEST--
2XMLReader: libxml2 XML Reader, attributes test
3--EXTENSIONS--
4xmlreader
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--EXPECT--
35books
36book
37   Attribute Name: num
38   Attribute Value: 1
39   Attribute Name: idx
40   Attribute Value: 2
41#text
42