creating nodes
domcreatemethods.php:
<?php

$dom 
= new DomDocument();

// create a new element 
$root $dom->createElement("root");

// append it to the document 
$root $dom->appendChild($root);

//create an element with a namespace and add it to the root
$ns $dom->createElementNs("http://foo/bar","namespaced");
$root->appendChild($ns);

//create a text node and append it to the root 
$root->appendChild($dom->createTextNode("\nHello World\n"));

//create a comment and append it to the document
$comment $dom->createComment("this is a comment");
$dom->appendChild($comment);

//add an attribute to the root element
$root->setAttribute("foo","bar");

//add cdata to root
$cdata $dom->createCdataSection("cdata with < and ' and > ");
$root->appendChild($cdata);

//add an entity reference
$entity $dom->createEntityReference("auml");
$root->appendChild($entity);

//add an processing instruction
$pi $dom->createProcessingInstruction("php","time();");
$root->appendChild($pi);

print 
htmlentities($dom->saveXML());
 
creating nodes © copyright 2004  Bitflux GmbH