xref: /PHP-7.3/ext/xmlreader/tests/012.phpt (revision 782352c5)
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', dirname(__FILE__).'/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 = dirname(__FILE__) . '/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(dirname(__FILE__) . '/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===DONE===
63--EXPECT--
64string(0) ""
65NULL
66string(0) ""
67string(0) ""
68
69Using URI:
70string(0) ""
71NULL
72string(0) ""
73string(0) ""
74===DONE===
75