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