(PHP 5, PHP 7)
Removes child from list of children
public DOMNode DOMNode::removeChild ( DOMNode $oldnode )
This functions removes a child from a list of children.
Parameters:
oldnode
The removed child.
Returns:
If the child could be removed the function returns the old child.
Exception:
Raised if this node is readonly.
Raised if oldnode
is not a child of this node.
Examples:
Removing a child
The following example will delete the chapter element of our XML document.
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?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(); ?> |
The above example will output:
<?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>
See also:
Please login to continue.