004.phpt 1005 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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$ */
  8. $filename = dirname(__FILE__) . '/_004.xml';
  9. $xmlstring = '<?xml version="1.0" encoding="UTF-8"?>
  10. <books><book num="1" idx="2">book1</book></books>';
  11. file_put_contents($filename, $xmlstring);
  12. $reader = new XMLReader();
  13. if (!$reader->open($filename)) {
  14. exit();
  15. }
  16. while ($reader->read()) {
  17. if ($reader->nodeType != XMLREADER::END_ELEMENT) {
  18. echo $reader->name."\n";
  19. if ($reader->nodeType == XMLREADER::ELEMENT && $reader->hasAttributes) {
  20. $attr = $reader->moveToFirstAttribute();
  21. while ($attr) {
  22. echo " Attribute Name: ".$reader->name."\n";
  23. echo " Attribute Value: ".$reader->value."\n";
  24. $attr = $reader->moveToNextAttribute();
  25. }
  26. }
  27. }
  28. }
  29. $reader->close();
  30. unlink($filename);
  31. ?>
  32. ===DONE===
  33. --EXPECT--
  34. books
  35. book
  36. Attribute Name: num
  37. Attribute Value: 1
  38. Attribute Name: idx
  39. Attribute Value: 2
  40. #text
  41. ===DONE===