note 29096 deleted from ref.domxml by sniper
| From: | sniper@php.net | Date: | Mon, 03 Nov 2003 15:47:12 +0000 |
| Subject: | note 29096 deleted from ref.domxml by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-59706@lists.php.net to get a copy of this message | ||
Note Submitter:
----
When working with DOM, be sure that you look at the DOM Interface Specification. The level 2 core
specification is loated at the link below:
http://www.w3.org/TR/DOM-Level-2-Core/core.html
Remember that the object hierarchy defined here is implemented also in PHP.
As a result, all Documents are Elements, and all Elements are Nodes. You do not need to convert
from elements to nodes before you add them to other elements.
Example:
<?php
/**
domtest.php: Proof of Concept for DOM XML
PHP version: 4.3.0
libxml-2.5.1
Your "View Source" from your browser should look like:
<?xml version="1.0"?>
<html><body><h1>Hello, how are you?</h1></body></html>
*/
// Create a new DomAttribute object
$dom = domxml_new_doc('1.0');
// Create elements
$htmlElement = $dom->create_element('html');
$bodyElement = $dom->create_element('body');
$headingElement = $dom->create_element('h1');
$headingTextElement = $dom->create_text_node("Hello, how are you?");
// Construct the XML document
$headingElement->add_child($headingTextElement);
$bodyElement->add_child($headingElement);
$htmlElement->add_child($bodyElement);
// Add the root element to the document
$dom->append_child($htmlElement);
// Output the document to the browser
echo $dom->dump_mem();
?>