Annotation of embedaddon/php/ext/xmlreader/tests/004.phpt, revision 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: 004.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: while ($reader->read()) {
! 20: if ($reader->nodeType != XMLREADER::END_ELEMENT) {
! 21: echo $reader->name."\n";
! 22: if ($reader->nodeType == XMLREADER::ELEMENT && $reader->hasAttributes) {
! 23: $attr = $reader->moveToFirstAttribute();
! 24: while ($attr) {
! 25: echo " Attribute Name: ".$reader->name."\n";
! 26: echo " Attribute Value: ".$reader->value."\n";
! 27: $attr = $reader->moveToNextAttribute();
! 28: }
! 29: }
! 30: }
! 31: }
! 32: $reader->close();
! 33: unlink($filename);
! 34: ?>
! 35: ===DONE===
! 36: --EXPECT--
! 37: books
! 38: book
! 39: Attribute Name: num
! 40: Attribute Value: 1
! 41: Attribute Name: idx
! 42: Attribute Value: 2
! 43: #text
! 44: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>