Removes child from list of children

DOMNode::removeChild

(PHP 5, PHP 7, PHP 8)

DOMNode::removeChild Removes child from list of children

說明

public DOMNode::removeChild(DOMNode $child): DOMNode|false

This functions removes a child from a list of children.

參數

child

The removed child.

返回值

If the child could be removed the function returns the old child.

錯誤/異常

DOM_NO_MODIFICATION_ALLOWED_ERR

Raised if this node is readonly.

DOM_NOT_FOUND

Raised if child is not a child of this node.

範例

The following example will delete the chapter element of our XML document.

示例 #1 Removing a child

<?php

$doc 
= new DOMDocument;
$doc->load('book.xml');

$book $doc->documentElement;

// we retrieve the chapter and remove it from the book
$chapter $book->getElementsByTagName('chapter')->item(0);
$oldchapter $book->removeChild($chapter);

echo 
$doc->saveXML();
?>

以上例程會輸出:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 
          "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
<book id="listing">
 <title>My lists</title>
 
</book>

參見

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *