012.phpt 1.8 KB

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