Create a new DOMElement object in PHP

Description

The following code shows how to create a new DOMElement object.

Example


/*  ww w  .  j  a v a 2  s  .  c  om*/
<?php

$dom = new DOMDocument('1.0', 'iso-8859-1');
$element = $dom->appendChild(new DOMElement('root'));
$element_ns = new DOMElement('pr:node1', 'thisvalue', 'http://java2s.com');
$element->appendChild($element_ns);
echo $dom->saveXML(); 
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    XML »




DOM
SimpleXML
SimpleXMLElement
XML Parser