IT. Expert System.

PHP

Removes child from list of children


DOMNode::removeChild

(PHP 5)

DOMNode::removeChild Removes child from list of children

Description

public DOMNode DOMNode::removeChild ( DOMNode $oldnode )

This functions removes a child from a list of children.

Parameters

oldnode

The removed child.

Return Values

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

Errors/Exceptions

DOM_NO_MODIFICATION_ALLOWED_ERR

Raised if this node is readonly.

DOM_NOT_FOUND

Raised if oldnode is not a child of this node.

Examples

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

Example #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();
?>

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> 

Example #2 Preserving the parent node's namespace URI

<?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);

// copy the namespace URI
$nsuri $book->namespaceURI;

// Delete the child node
$book->removeChild($chapter);

// paste the namespace URI back into the parent node
$book->namespaceURI $nsuri;
?>

Notes

Note:

After calling this method, the DOMNode::$namespaceURI property on the parent node will be reset to NULL. Above example shows how to work around it.

See Also



Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 2182 / . Delta: 0.02238 с