xref: /PHP-8.0/ext/xmlreader/tests/012.phpt (revision f8d79582)
1--TEST--
2XMLReader: accessing empty and non existing attributes
3--SKIPIF--
4<?php if (!extension_loaded("xmlreader")) print "skip"; ?>
5--FILE--
6<?php
7
8$xmlstring =<<<EOF
9<?xml version="1.0" encoding="UTF-8"?>
10<foo bar=""/>
11EOF;
12
13$reader = new XMLReader();
14$reader->XML($xmlstring);
15$reader->read();
16var_dump($reader->getAttribute('bar'));
17var_dump($reader->getAttribute('baz'));
18$reader->close();
19
20$xmlstring =<<<EOF
21<?xml version="1.0" encoding="UTF-8"?>
22<!DOCTYPE foo SYSTEM "012.dtd">
23<foo bar=""/>
24EOF;
25
26$xmlstring = str_replace('012.dtd', __DIR__.'/012.dtd', $xmlstring);
27if (DIRECTORY_SEPARATOR == '\\') {
28    $xmlstring = str_replace('\\',"/", $xmlstring);
29}
30$reader = new XMLReader();
31$reader->XML($xmlstring);
32$reader->setParserProperty(XMLReader::DEFAULTATTRS, true);
33while($reader->read() && $reader->nodeType != XMLReader::ELEMENT);
34var_dump($reader->getAttribute('bar'));
35var_dump($reader->getAttribute('baz'));
36$reader->close();
37
38echo "\nUsing URI:\n";
39$reader = new XMLReader();
40$file = __DIR__ . '/012.xml';
41if (DIRECTORY_SEPARATOR == '\\') {
42    $file = str_replace('\\',"/", $file);
43}
44
45$reader->open($file);
46
47//$reader->setParserProperty(XMLReader::DEFAULTATTRS, true);
48while($reader->read() && $reader->nodeType != XMLReader::ELEMENT);
49var_dump($reader->getAttribute('bar'));
50var_dump($reader->getAttribute('baz'));
51$reader->close();
52
53$reader = new XMLReader();
54$reader->open(__DIR__ . '/012.xml');
55$reader->setParserProperty(XMLReader::DEFAULTATTRS, true);
56while($reader->read() && $reader->nodeType != XMLReader::ELEMENT);
57var_dump($reader->getAttribute('bar'));
58var_dump($reader->getAttribute('baz'));
59$reader->close();
60
61?>
62--EXPECT--
63string(0) ""
64NULL
65string(0) ""
66string(0) ""
67
68Using URI:
69string(0) ""
70NULL
71string(0) ""
72string(0) ""
73