dom006.phpt 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. --TEST--
  2. Test 6: Extends Test
  3. --EXTENSIONS--
  4. dom
  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(__DIR__."/book.xml");
  21. $dom->addBook("PHP de Luxe", "Richard Samar, Christian Stocker");
  22. print $dom->saveXML();
  23. ?>
  24. --EXPECT--
  25. <?xml version="1.0"?>
  26. <books>
  27. <book>
  28. <title>The Grapes of Wrath</title>
  29. <author>John Steinbeck</author>
  30. </book>
  31. <book>
  32. <title>The Pearl</title>
  33. <author>John Steinbeck</author>
  34. </book>
  35. <book><title>PHP de Luxe</title><author>Richard Samar, Christian Stocker</author></book></books>