012.phpt 754 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. --TEST--
  2. SimpleXML: Attribute creation
  3. --EXTENSIONS--
  4. simplexml
  5. --FILE--
  6. <?php
  7. $xml =<<<EOF
  8. <?xml version="1.0" encoding="ISO-8859-1" ?>
  9. <foo/>
  10. EOF;
  11. $sxe = simplexml_load_string($xml);
  12. try {
  13. $sxe[""] = "value";
  14. } catch (ValueError $exception) {
  15. echo $exception->getMessage() . "\n";
  16. }
  17. $sxe["attr"] = "value";
  18. echo $sxe->asXML();
  19. $sxe["attr"] = "new value";
  20. echo $sxe->asXML();
  21. try {
  22. $sxe[] = "error";
  23. } catch (ValueError $exception) {
  24. echo $exception->getMessage() . "\n";
  25. }
  26. __HALT_COMPILER();
  27. ?>
  28. ===DONE===
  29. --EXPECT--
  30. Cannot create attribute with an empty name
  31. <?xml version="1.0" encoding="ISO-8859-1"?>
  32. <foo attr="value"/>
  33. <?xml version="1.0" encoding="ISO-8859-1"?>
  34. <foo attr="new value"/>
  35. Cannot append to an attribute list