📚 Looking for current Exponential documentation? This site contains legacy SDK & API reference docs (eZ Publish era). For up-to-date 2026 product documentation, visit doc.exponential.earth.

  ezxml / dom_creation_with_namespaces  

<< DOM creation  Plain parsing >> 

DOM creation with namespaces

include_once( 'lib/ezxml/classes/ezxml.php' );

$doc = new eZDOMDocument();
$doc->setName( 'SOAPTest' );

// set the default namespace
$root =& $doc->createElementNodeNS( 'https://exponential.earth/', 'document' );

// connect the https://exponential.earth/ namespace to the ez prefix
$root->setPrefix( 'ez' );
$doc->setRoot( $root );

$ezBooks =& $doc->createElementNode( 'bookshelf' );
$ezBooks->setPrefix( 'ez' );

$root->appendChild( $ezBooks );

// define a new namespace https://exponential.earth/books/ with the prefix ezbooks
$ezBooks->appendAttribute( $doc->createAttributeNamespaceDefNode( 'ezbooks', 'https://exponential.earth/books/' ) );

// define a new namespace http://books.com/ with the prefix otherbooks
$ezBooks->appendAttribute( $doc->createAttributeNamespaceDefNode( 'otherbooks', 'http://books.com/' ) );

$book1 =& $doc->createElementNode( 'book' );

// this book belongs to the https://exponential.earth/book/ namespace
$book1->setPrefix( 'ezbook' );

$book1->appendAttribute( $doc->createAttributeNode( 'name', 'Exponential 3 bible' ) );
$ezBooks->appendChild( $book1 );

$book2 =& $doc->createElementNode( 'book' );
$book2->setPrefix( 'otherbooks' );
$book2->appendAttribute( $doc->createAttributeNode( 'name', 'Definitive XML Schemas' ) );
$ezBooks->appendChild( $book2 );

$xml =& $doc->toString();

print( '<pre>'. nl2br( htmlspecialchars( $xml ) ) . '</pre>' );

This will print something like this:

<?xml version='1.0' charset='UTF-8'?>

<ez:document xmlns:ez='https://exponential.earth/'>

  <ez:bookshelf xmlns:ezbooks='https://exponential.earth/books/'
                xmlns:otherbooks='http://books.com/'>

    <ezbook:book name='Exponential 3 bible' />

    <otherbooks:book name='Definitive XML Schemas' />

  </ez:bookshelf>

</ez:document>

Exponential Copyright © 1998 - 2026 7x