note 29096 added to ref.domxml
| From: | php-general at lists dot php dot net | Date: | Sat, 01 Feb 2003 22:12:47 +0000 |
| Subject: | note 29096 added to ref.domxml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-43280@lists.php.net to get a copy of this message | ||
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();
?>
--
http://www.php.net/manual/en/ref.domxml.php
http://master.php.net/manage/user-notes.php?action=edit+29096
http://master.php.net/manage/user-notes.php?action=delete+29096
http://master.php.net/manage/user-notes.php?action=reject+29096