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.
DomDocument::create_element
(PHP 4 >= 4.1.0)
DomDocument::create_element — Yeni bir eleman düğümü oluşturur
Açıklama
Belirtilen ismi kullanarak yeni bir eleman düğümü oluşturur. Bu düğüm, DomNode::append_child() gibi bir yöntemle belgeye yerleştirilmedikçe belgede gösterilmez.
Dönen Değerler
Bir hata oluşursa FALSE yoksa bir DomElement nesnesi döndürür.
Ayrıca Bakınız
- DomDocument::create_element_ns() - Belirtilen isim alanı ile ilişkilendirerek yeni bir eleman düğümü oluşturur
- DomNode::append_child() - Düğüme en küçük çocuk olarak bir çocuk ekler
- DomDocument::create_text_node() - Yeni bir metin düğümü oluşturur
- DomDocument::create_cdata_section() - Yeni bir CDATA düğümü oluşturur
- DomDocument::create_comment() - Yeni bir açıklama düğümü oluşturur
- DomDocument::create_processing_instruction() - Yeni bir işlem komutu düğümü oluşturur
- DomDocument::create_entity_reference() - Yeni bir öğe gönderimi oluşturur
- DomDocument::create_attribute() - Yeni bir öznitelik düğümü oluşturur
- DomNode::insert_before() - Düğümün öncesine yeni bir düğüm yerleştirir
arimbourg at ariworld dot eu
16-Mar-2009 07:59
Mikael Ljungberg
03-May-2005 04:46
When creating empty nodes like xhtml:link, the output misses the closing slash. This is what I got:
<link ...>
dk
24-Nov-2003 04:58
The first example on this page is also a bit verbose. Since the DomElement class inherits/extends the DomNode class, one does not, in fact, have to get another reference to the first node. The create_element method has already given you that reference. (Also, the last line passes a string to the append_child method, instead of a DomNode object) Simplified:
<?
$new_element = $dom->create_element("new_element");
$new_element->append_child($another_element);
$oldTag->append_child($new_element);
?>
Jorrit Kronjee
05-Nov-2003 12:15
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);
Nico almhoedi at gmx dot de
04-Jan-2003 08:40
It's easier possible since DomNode->append_child($new_element) returns the new child as an object, so you can refer to it immediately.
To append a child to the node $existent_node:
$new_element = DomDocument->create_element("new_el");
$new_node = $existent_node->append_child("new_el");
see Manual DomNode->append_child()
greg@cabinetuk
13-Nov-2002 10:27
Its important to remember, when adding a created element to an existing node using append_child(), that if you want to then add another element to that node you have to go back and set up a DOMNode instance using DOMDocument_get_elements_by_tagname or similar before you can append another node onto it.
eg
<?
$new_element = $dom->create_element("new_element");
$oldTag->append_child($new_element);
//Go back and set up new element as DOMNode
$new_elementArray = $dom->get_elements_by_tagname("new_element");
$new_elementTag = $new_elementArray[0];//(if theres more than one use a for loop)
$new_elementTag->append_child("another_new_element");
?>
