xref: /PHP-7.4/ext/dom/tests/dom006.phpt (revision 26dfce7f)
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--EXPECT--
30<?xml version="1.0"?>
31<books>
32 <book>
33  <title>The Grapes of Wrath</title>
34  <author>John Steinbeck</author>
35 </book>
36 <book>
37  <title>The Pearl</title>
38  <author>John Steinbeck</author>
39 </book>
40<book><title>PHP de Luxe</title><author>Richard Samar, Christian Stocker</author></book></books>
41