DOM XML functionsDOM XMLIntroduction
&warn.experimental;
The domxml extension has been overhauled in PHP Version 4.3.0 in favour
of a better compliance of the DOM standard. The extension still contains
many old functions, but they should not be used anymore. Especially those
non object oriented functions should be avoided.
The extension allows you to operate on an XML document with the DOM API.
It also provides a function domxml_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 DomDocument_dump_mem
cannot be
applied to it. Therefore, if you want to read an XML file and write
a modified version use the DomDocument_create_element,
DomDocument_create_text,
set_attribute, etc. and finally
DomDocument_dump_mem functions.
Requirements
This extension is only available if PHP was configured with
, using the
GNOME xml library.
You will need at least libxml-2.2.7
Deprecated functions
There a quite some functions which do not fit into the DOM standard and
should not be used anymore as listed in the following table.
The function DomNode_append_child has changed its
behaviour. It now actually adds a child and not a sibling. If this
breaks your application use the non DOM function
DomNode_append_sibling.
Deprecated functions and its replacementsOld functionNew functionxmldocdomxml_open_memxmldocfieldomxml_open_filedomxml_new_xmldocdomxml_new_docdomxml_dump_memDomDocument_dump_memdomxml_dump_mem_fileDomDocument_dump_fileDomDocument_dump_mem_fileDomDocument_dump_fileDomDocument_add_rootDomDocument_create_element followed by
DomNode_append_childDomDocument_dtdDomDocument_doctypeDomDocument_rootDomDocument_document_elementDomDocument_childrenDomNode_child_nodesDomDocument_imported_nodeNo replacement.DomNode_add_childCreate a new node with e.g.
DomDocument_create_element und add it with
DomNode_append_child.
DomNode_childrenDomNode_child_nodesDomNode_parentDomNode_parent_nodeDomNode_new_childCreate a new node with e.g.
DomDocument_create_element und add it with
DomNode_append_child.
DomNode_set_contentCreate a new node with e.g.
DomDocument_create_text_node und add it with
DomNode_append_child.
DomNode_get_contentContent is just a text node and can be accessed with
DomNode_child_nodes.
DomNode_set_contentContent is just a text node and can be added with
DomNode_append_child.
Constants
This module defines the following constants:
XML constantsConstantValueDescriptionXML_ELEMENT_NODE1Node is an elementXML_ATTRIBUTE_NODE2Node is an attributeXML_TEXT_NODE3Node is a piece of textXML_CDATA_SECTION_NODE4XML_ENTITY_REF_NODE5XML_ENTITY_NODE6Node is an entity like XML_PI_NODE7Node is a processing instructionXML_COMMENT_NODE8Node is a commentXML_DOCUMENT_NODE9Node is a documentXML_DOCUMENT_TYPE_NODE10XML_DOCUMENT_FRAG_NODE11XML_NOTATION_NODE12XML_GLOBAL_NAMESPACE1XML_LOCAL_NAMESPACE2
Classes
The API of the module follows the DOM Level 2 standard as close
as possible. Consequently the API is fully object oriented.
It is a good idea to have the DOM standard available when
using this module.
Though the API is object oriented there are many functions which can
be called in a non-object oriented way by passing the object to operate
on as the first argument. These function are mainly to retain compatibilty
to older versions of the extension but are not encouraged to use anymore
in new developments.
This API differs from the official DOM API in two points. First, all
class attributes are implemented as functions with the same name and
secondly the function names follow the PHP naming convention. This means
that a DOM function lastChild() will be written as last_child().
This module defines a number of classes, which are listed —
including their
method — in the following tables. Classes with an equivalent in the
DOM Standard are named DOMxxx.
List of classesClass nameParent classesDomAttributeDomNodeDomCDataDomNodeDomCommentDomCData : DomNodeDomDocumentDomNodeDomDocumentTypeDomNodeDomElementDomNodeDomEntityDomNodeDomEntityReferenceDomNodeDomProcessingInstructionDomNodeDomTextDomCData : DomNodeParserCurrently still called DomParserXPathContext
DomDocument class (DomDocument : DomNode)Method nameFunction nameRemarkdoctypeDomDocument_doctypedocument_elemnentDomDocument_document_elementcreate_elementDomDocument_create_elementcreate_text_nodeDomDocument_create_text_nodecreate_commentDomDocument_create_commentcreate_cdata_sectionDomDocument_create_cdata_sectioncreate_processing_instructionDomDocument_create_processing_instructioncreate_attributeDomDocument_create_attributecreate_entity_referenceDomDocument_create_entity_referenceget_elements_by_tagnameDomDocument_get_elements_by_tagnameget_element_by_idDomDocument_get_element_by_iddump_memDomDocument_dump_memnot DOM standarddump_fileDomDocument_dump_filenot DOM standardhtml_dump_memDomDocument_html_dump_memnot DOM standardxpath_initxpath_initnot DOM standardxpath_new_contextxpath_new_contextnot DOM standardxptr_new_contextxptr_new_contextnot DOM standard
DomElement class (DomElement : DomNode)Method nameFunction nameRemarktagnameDomElement_tagnameget_attributeDomElement_get_attributeset_attributeDomElement_set_attributeremove_attributeDomElement_remove_attributeget_attribute_nodeDomElement_get_attribute_nodeset_attribute_nodeDomElement_set_attribute_nodeget_elements_by_tagnameDomElement_get_elements_by_tagnamehas_attributeDomElement_has_attribute
DomNode classMethod nameRemarkDomNode_node_nameDomNode_node_valueDomNode_node_typeDomNode_last_childDomNode_first_childDomNode_child_nodesDomNode_previous_siblingDomNode_next_siblingDomNode_parent_nodeDomNode_owner_documentDomNode_insert_beforeDomNode_append_childDomNode_append_siblingNot in DOM standard. This function emulates the former
behaviour of DomNode_append_child.DomNode_remove_childDomNode_has_child_nodesDomNode_has_attributesDomNode_clone_nodeDomNode_attributesDomNode_unlink_nodeNot in DOM standardDomNode_replace_nodeNot in DOM standardDomNode_set_contentNot in DOM standard, deprecatedDomNode_get_contentNot in DOM standard, deprecatedDomNode_dump_nodeNot in DOM standardDomNode_is_blank_nodeNot in DOM standard
DomAttribute class (DomAttribute : DomNode)Method nameRemarknameDomAttribute_namevalueDomAttribute_valuespecifiedDomAttribute_specified
DomProcessingInstruction class (DomProcessingInstruction : DomNode)Method nameFunction nameRemarktargetDomProcessingInstruction_targetdataDomProcessingInstruction_data
DomDocumentType class (DomDocumentType : DomNode)Method nameFunction nameRemarknameDomDocumentType_nameentitiesDomDocumentType_entitiesnotationsDomDocumentType_notationspublic_idDomDocumentType_public_idsystem_idDomDocumentType_system_idinternal_subsetDomDocumentType_internal_subset
The classes DomDtd is derived from DomNode. DomComment is derived from
DomCData
Examples
Many examples in this reference require a xml string. Instead of
repeating this string in any example it will be put into a file
and be included by each example. This include file is shown in the
following example section. You could also create an xml document
read it with DomDocument_open_file.
Include file example.inc with xml string
]>
Title
&sp;
a1b1c1a2c2a3b3c3";
?>
]]>
&reference.domxml.functions;