CakeFest 2017 NYC, the Official CakePHP Conference


(PHP 4 >= 4.1.0)

DomDocument->create_elementCreate new element node


domelement DomDocument->create_element ( string $name )

This function returns a new instance of class DomElement. The tag name of the element is the value of the passed parameter. This node will not show up in the document unless it is inserted with (e.g.) domnode_append_child().

The return value is FALSE if an error occurred.

See also domdocument_create_element_ns(), domnode_append_child(), domdocument_create_text(), domdocument_create_comment(), domdocument_create_attribute(), domdocument_create_processing_instruction(), domdocument_create_entity_reference(), and domnode_insert_before().

add a note add a note

User Contributed Notes 3 notes

arimbourg at ariworld dot eu
7 years ago
It seem that the domDocument 'create_element' method don't work anymore in php 5.2.6.
We have to use the DOM 'createElement' instead.
Mikael Ljungberg
11 years ago
When creating empty nodes like xhtml:link, the output misses the closing slash. This is what I got:

<link ...>
Jorrit Kronjee
13 years ago
The example done by Nico Almhoedi has a small error.

Since append_child only accepts DomElement (which is an object), it should've been:

$new_element = DomDocument->create_element("new_el");
$new_node = $existent_node->append_child($new_element);
To Top