summaryrefslogtreecommitdiff
path: root/ext/xmlreader/tests/003-mb.phpt
blob: 43d47f590899ef80fc3110e829fedff9aa7b3c6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
--TEST--
XMLReader: libxml2 XML Reader, attributes test 
--SKIPIF--
<?php if (!extension_loaded("xmlreader")) print "skip"; ?>
--FILE--
<?php 
$filename = dirname(__FILE__) . '/私はガラスを食べられます_003.xml';

$xmlstring = '<?xml version="1.0" encoding="UTF-8"?>
<books><book num="1" idx="2">book1</book></books>';
file_put_contents($filename, $xmlstring);

$reader = new XMLReader();
if (!$reader->open($filename)) {
	exit();
}

// Only go through
while ($reader->read()) {
	if ($reader->nodeType != XMLREADER::END_ELEMENT) {
		if ($reader->nodeType == XMLREADER::ELEMENT && $reader->hasAttributes) {
			$attr = $reader->moveToFirstAttribute();
			echo $reader->name . ": ";
			echo $reader->value . "\n";

			if ($reader->getAttribute($reader->name) == $reader->value) {
				echo "1st attr (num) failed\n";
			}


			$attr = $reader->moveToNextAttribute();
			echo $reader->name . ": ";
			echo $reader->value . "\n";

			if ($reader->getAttribute($reader->name) == $reader->value) {
				echo "2nd attr (idx) failed\n";
			}

			// Named attribute
			$attr = $reader->moveToAttribute('num');
			echo $reader->name . ": ";
			echo $reader->value . "\n";

			if ($reader->getAttribute('num') == $reader->value) {
				echo "attr num failed\n";
			}

			$attr = $reader->moveToAttribute('idx');
			echo $reader->name . ": ";
			echo $reader->value . "\n";

			if ($reader->getAttribute('idx') == $reader->value) {
				echo "attr idx failed\n";
			}

			// Numeric positions of attributes
			$attr = $reader->moveToAttributeNo(0);
			echo $reader->name . ": ";
			echo $reader->value . "\n";

			if ($reader->getAttributeNo(0) == $reader->value) {
				echo "attr 0 failed\n";
			}

			$attr = $reader->moveToAttributeNo(1);
			echo $reader->name . ": ";
			echo $reader->value . "\n";

		}
	}
}
$reader->close();
unlink($filename);
?>
===DONE===
--EXPECT--
num: 1
idx: 2
num: 1
idx: 2
num: 1
idx: 2
===DONE===