Annotation of embedaddon/php/ext/xmlreader/tests/003.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: XMLReader: libxml2 XML Reader, attributes test
3: --SKIPIF--
4: <?php if (!extension_loaded("xmlreader")) print "skip"; ?>
5: --FILE--
6: <?php
7: /* $Id: 003.phpt 204555 2006-01-04 19:44:46Z rrichards $ */
8: $filename = dirname(__FILE__) . '/_002.xml';
9:
10: $xmlstring = '<?xml version="1.0" encoding="UTF-8"?>
11: <books><book num="1" idx="2">book1</book></books>';
12: file_put_contents($filename, $xmlstring);
13:
14: $reader = new XMLReader();
15: if (!$reader->open($filename)) {
16: exit();
17: }
18:
19: // Only go through
20: while ($reader->read()) {
21: if ($reader->nodeType != XMLREADER::END_ELEMENT) {
22: if ($reader->nodeType == XMLREADER::ELEMENT && $reader->hasAttributes) {
23: $attr = $reader->moveToFirstAttribute();
24: echo $reader->name . ": ";
25: echo $reader->value . "\n";
26:
27: if ($reader->getAttribute($reader->name) == $reader->value) {
28: echo "1st attr (num) failed\n";
29: }
30:
31:
32: $attr = $reader->moveToNextAttribute();
33: echo $reader->name . ": ";
34: echo $reader->value . "\n";
35:
36: if ($reader->getAttribute($reader->name) == $reader->value) {
37: echo "2nd attr (idx) failed\n";
38: }
39:
40: // Named attribute
41: $attr = $reader->moveToAttribute('num');
42: echo $reader->name . ": ";
43: echo $reader->value . "\n";
44:
45: if ($reader->getAttribute('num') == $reader->value) {
46: echo "attr num failed\n";
47: }
48:
49: $attr = $reader->moveToAttribute('idx');
50: echo $reader->name . ": ";
51: echo $reader->value . "\n";
52:
53: if ($reader->getAttribute('idx') == $reader->value) {
54: echo "attr idx failed\n";
55: }
56:
57: // Numeric positions of attributes
58: $attr = $reader->moveToAttributeNo(0);
59: echo $reader->name . ": ";
60: echo $reader->value . "\n";
61:
62: if ($reader->getAttributeNo(0) == $reader->value) {
63: echo "attr 0 failed\n";
64: }
65:
66: $attr = $reader->moveToAttributeNo(1);
67: echo $reader->name . ": ";
68: echo $reader->value . "\n";
69:
70: }
71: }
72: }
73: $reader->close();
74: unlink($filename);
75: ?>
76: ===DONE===
77: --EXPECT--
78: num: 1
79: idx: 2
80: num: 1
81: idx: 2
82: num: 1
83: idx: 2
84: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>