PHP Wysardry
PHP Manual

PHP documentation.



Home / PHP / Manual / ...



PHP Manual
Prev Next

XXV. DOM XML functions

Warning

This extension is EXPERIMENTAL. The behaviour of this extension, including the names of its functions, and anything else documented about this extension may change in a future release of PHP without notice. Be warned and use this extension at your own risk.

This documentation is not finished yet. Don't start to translate it or use it as a programming reference (steinm@php.net).

These functions are only available if PHP was configured with --with-dom=[DIR], using the GNOME xml library. You will need at least libxml-2.2.7 These functions have been added in PHP 4.

The extension allows you to operate on an XML document with the DOM API. It also provides a function xmltree() to turn the complete XML document into a tree of PHP objects. Currently this tree should be considered read-only - you can modify it but this would not make any sense since dumpmem() cannot be applied to it. Therefore, if you want to read an XML file and write a modified version use the add_node(), set_attribute(), etc. and finally dumpmem() functions.

This module defines the following constants:

Table 1. XML constants

Constant Value Description
XML_ELEMENT_NODE 1 Node is an element
XML_ATTRIBUTE_NODE 2 Node is an attribute
XML_TEXT_NODE 3 Node is a piece of text
XML_CDATA_SECTION_NODE 4  
XML_ENTITY_REF_NODE 5  
XML_ENTITY_NODE 6 Node is an entity like ∓nbsp;
XML_PI_NODE 7 Node is a processing instruction
XML_COMMENT_NODE 8 Node is a comment
XML_DOCUMENT_NODE 9 Node is a document
XML_DOCUMENT_TYPE_NODE 10  
XML_DOCUMENT_FRAG_NODE 11  
XML_NOTATION_NODE 12  
XML_GLOBAL_NAMESPACE 1  
XML_LOCAL_NAMESPACE 2  

Each function in this extension can be used in two ways. In a non-object oriented way by passing the object to apply the function to as a first argument, or in an object oriented way by calling the function as a method of an object. This documentation describes the non-object oriented functions, though you get the object methods by skipping the prefix "domxml_".

This module defines a number of classes, which are listed — including their properties and method — in the following table.

Table 2. DomDocument class (methods)

Method name Function name Description
root domxml_root()  
children domxml_children()  
add_root domxml_add_root()  
dtd domxml_intdtd()  
dumpmem domxml()  
xpath_init xpath_init  
xpath_new_context xpath_new_context  
xptr_new_context xptr_new_context  

Table 3. DomDocument class (attributes)

Name Type Description
doc class DomDocument The object itself
name string  
url string  
version string Version of XML
encoding string  
standalone long 1 if the file is a standalone version
type long One of the constants in table ...
compression long 1 if the file is compressed
charset long  

Table 4. DomNode class (methods)

Name PHP name Description
lastchild domxml_last_child()  
children domxml_children()  
parent domxml_parent()  
new_child domxml_new_child()  
get_attribute domxml_get_attribute()  
set_attribute domxml_set_attribute()  
attributes domxml_attributes()  
node domxml_node()  
set_content() domxml_set_content  

Table 5. DomNode class (attributes)

Name Type Description
node class DomNode The object itself
type long  
name string  
content string  
Table of Contents
xmldoc -- Creates a DOM object of an XML document
xmldocfile -- Creates a DOM object from XML file
xmltree --  Creates a tree of PHP objects from XML document
domxml_root --  Returns root element node
domxml_add_root --  Adds a further root node
domxml_dumpmem --  Dumps the internal XML tree back into a string
domxml_attributes --  Returns an array of attributes of a node
domxml_get_attribute --  Returns a certain attribute of a node
domxml_set_attribute -- 
domxml_children --  Returns children of a node or document
domxml_new_child --  Adds new child node
domxml_new_xmldoc --  Creates new empty XML document
xpath_new_context --  Creates new xpath context
xpath_eval --  Evaluates the XPath Location Path in the given string
domxml_node --  Creates node
domxml_node_set_content --  Sets content of a node
domxml_node_unlink_node --  Deletes node
xpath_eval_expression --  Evaluates the XPath Location Path in the given string
domxml_version --  Get XML library version
xptr_new_context --  Create new XPath Context
xptr_eval --  Evaluate the XPtr Location Path in the given string

Prev Manual Home Next
rewinddir Up xmldoc
Site Menu

Amazon.ca
Amazon.com
Amazon.co.uk



Most recently updated on 11 May, 2003

Home / PHP / Manual / ...



Please feel free to contact us with any comments or suggestions
PHP Manual
PHP Wysardry

This site is hosted by Spaceports