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