dom006.phpt 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. --TEST--
  2. Test 6: Extends Test
  3. --SKIPIF--
  4. <?php require_once('skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. Class books extends domDocument {
  8. function addBook($title, $author) {
  9. $titleElement = $this->createElement("title");
  10. $titleElement->appendChild($this->createTextNode($title));
  11. $authorElement = $this->createElement("author");
  12. $authorElement->appendChild($this->createTextNode($author));
  13. $bookElement = $this->createElement("book");
  14. $bookElement->appendChild($titleElement);
  15. $bookElement->appendChild($authorElement);
  16. $this->documentElement->appendChild($bookElement);
  17. }
  18. }
  19. $dom = new books;
  20. $dom->load(dirname(__FILE__)."/book.xml");
  21. $dom->addBook("PHP de Luxe", "Richard Samar, Christian Stocker");
  22. print $dom->saveXML();
  23. --EXPECT--
  24. <?xml version="1.0"?>
  25. <books>
  26. <book>
  27. <title>The Grapes of Wrath</title>
  28. <author>John Steinbeck</author>
  29. </book>
  30. <book>
  31. <title>The Pearl</title>
  32. <author>John Steinbeck</author>
  33. </book>
  34. <book><title>PHP de Luxe</title><author>Richard Samar, Christian Stocker</author></book></books>