XXIV. DOM XML

Note importante : cette documentation est en cours de rédaction, et n'est pas encore finie. Elle souffre naturellement d'un manque de détails et de relecture. Soyez en prévenu. (Damien Seguy).

Ces fonctions ne sont disponibles que si PHP a été configuré avec l'option --with-dom=[DIR], et utilise la librairie GNOME xml library. Vous aurez aussi besoin de la librairie libxml-2.2.7 (la version beta ne fonctionne pas). Ces fonctions ont été ajoutées en PHP 4.

Cette extension vous permet de générer des documents XML avec les API DOM. Elle fournit aussi une fonction xmltree() qui transforme un fichier XML en tableau PHP. Actuellement, ce tableau est accessible uniquement en lecture. Cela ne siginifie pas que vous ne pouvez pas le modifier, mais cela n'aurait aucun sens car domxml_dumpmem() ne pourra pas prendre ces modifications en considération. Par conséquent, si vous voulez lire un fichier XML et écrire sa version modifiée, utilisez les fonctions domxml_add_node(), domxml_set_attribute(), etc... et finalement domxml_dumpmem().

Ce module définit les constantes suivantes :

Tableau 1. Constantes XML

ConstanteValeurDescription
XML_ELEMENT_NODE1Le noeud est un élément
XML_ATTRIBUTE_NODE2Le noeud est un attribut
XML_TEXT_NODE3Le noeud est un texte
XML_CDATA_SECTION_NODE4 
XML_ENTITY_REF_NODE5 
XML_ENTITY_NODE6Le noeud est une entité telle que  
XML_PI_NODE7Le noeud est une instruction
XML_COMMENT_NODE8Le noeud est un commentaire
XML_DOCUMENT_NODE9Le noeud est un document
XML_DOCUMENT_TYPE_NODE10 
XML_DOCUMENT_FRAG_NODE11 
XML_NOTATION_NODE12 
XML_GLOBAL_NAMESPACE1 
XML_LOCAL_NAMESPACE2 

Chaque fonction de cette extension peut être utilisée de deux manières différentes. Dans un contexte procédural, il faut passer l'objet en premier argument; dans un contexte objet, vous pouvez appeler la fonction comme une méthode de cet objet. Cette documentation présente les fonctions dans leur contexte procédural. Vous pouvez connaître la méthode objet en supprimant le préfixe "domxml_". Les tables suivantes listes toutes les classes, leurs attributs et leurs méthodes.

Ce module définit un ensemble de classes, qui sont listées ci-dessous (y compris leur attributs et leur méthodes).

Tableau 2. classe DomDocument (méthodes)

Nom de la méthodeNom de la fonctionDescription
rootdomxml_root() 
childrendomxml_children() 
add_rootdomxml_add_root() 
dtddomxml_intdtd() 
dumpmemdomxml_dumpmem() 
xpath_initxpath_init 
xpath_new_contextxpath_new_context 
xptr_new_contextxptr_new_context 

Tableau 3. Classe DomDocument (attributs)

NomTypeDescription
docclass DomDocumentL'objet lui-même
namestring 
urlstring 
versionstringVersion de XML
encodingstring 
standalonelong1 si le fichier est complet
typelongUne des constantes de la table ...
compressionlong1 si le fichier est compressé
charsetlong 

Tableau 4. classe DomNode (méthodes)

NomNom en PHPDescription
lastchilddomxml_last_child() 
childrendomxml_children() 
parentdomxml_parent() 
new_childdomxml_new_child() 
get_attributedomxml_get_attribute() 
set_attributedomxml_set_attribute() 
attributesdomxml_attributes() 
nodedomxml_node() 
set_content()domxml_set_content 

Tableau 5. classe DomNode (attributs)

NomTypeDescription
nodeclass DomNodeL'objet lui-même
typelong 
namestring 
contentstring 

Table des matières
DomAttribute->name --  Returns name of attribute
DomAttribute->specified --  Checks if attribute is specified
DomAttribute->value --  Returns value of attribute
DomDocument->add_root [deprecated] --  Adds a root node
DomDocument->create_attribute -- Create new attribute
DomDocument->create_cdata_section -- Create new cdata node
DomDocument->create_comment -- Create new comment node
DomDocument->create_element_ns --  Create new element node with an associated namespace
DomDocument->create_element -- Create new element node
DomDocument->create_entity_reference -- 
DomDocument->create_processing_instruction -- Creates new PI node
DomDocument->create_text_node -- Create new text node
DomDocument->doctype --  Returns the document type
DomDocument->document_element --  Returns root element node
DomDocument->dump_file --  Dumps the internal XML tree back into a file
DomDocument->dump_mem --  Dumps the internal XML tree back into a string
DomDocument->get_element_by_id --  Searches for an element with a certain id
DomDocument->get_elements_by_tagname -- 
DomDocument->html_dump_mem --  Dumps the internal XML tree back into a string as HTML
DomDocument->xinclude --  Substitutes XIncludes in a DomDocument Object.
DomDocumentType->entities --  Returns list of entities
DomDocumentType->internal_subset --  Returns internal subset
DomDocumentType->name --  Returns name of document type
DomDocumentType->notations --  Returns list of notations
DomDocumentType->public_id --  Returns public id of document type
DomDocumentType->system_id --  Returns system id of document type
DomElement->get_attribute_node --  Returns value of attribute
DomElement->get_attribute --  Returns value of attribute
DomElement->get_elements_by_tagname --  Gets elements by tagname
DomElement->has_attribute --  Checks to see if attribute exists
DomElement->remove_attribute --  Removes attribute
DomElement->set_attribute --  Adds new attribute
DomElement->tagname --  Returns name of element
DomNode->add_namespace --  Adds a namespace declaration to a node.
DomNode->append_child --  Adds new child at the end of the children
DomNode->append_sibling --  Adds new sibling to a node
DomNode->attributes --  Returns list of attributes
DomNode->child_nodes --  Returns children of node
DomNode->clone_node --  Clones a node
DomNode->dump_node --  Dumps a single node
DomNode->first_child --  Returns first child of node
DomNode->get_content --  Gets content of node
DomNode->has_attributes --  Checks if node has attributes
DomNode->has_child_nodes --  Checks if node has children
DomNode->insert_before --  Inserts new node as child
DomNode->is_blank_node --  Checks if node is blank
DomNode->last_child --  Returns last child of node
DomNode->next_sibling --  Returns the next sibling of node
DomNode->node_name --  Returns name of node
DomNode->node_type --  Returns type of node
DomNode->node_value --  Returns value of a node
DomNode->owner_document --  Returns the document this node belongs to
DomNode->parent_node --  Returns the parent of the node
DomNode->prefix --  Returns name space prefix of node
DomNode->previous_sibling --  Returns the previous sibling of node
DomNode->remove_child --  Removes child from list of children
DomNode->replace_child --  Replaces a child
DomNode->replace_node --  Replaces node
DomNode->set_content --  Sets content of node
DomNode->set_name --  Sets name of node
DomNode->set_namespace --  Sets namespace of a node.
DomNode->unlink_node --  Deletes node
DomProcessingInstruction->data --  Returns data of pi node
DomProcessingInstruction->target --  Returns target of pi node
DomXsltStylesheet->process --  Applies the XSLT-Transformation on a DomDocument Object.
DomXsltStylesheet->result_dump_file --  Dumps the result from a XSLT-Transformation into a file
DomXsltStylesheet->result_dump_mem --  Dumps the result from a XSLT-Transformation back into a string
domxml_new_doc --  Creates new empty XML document
domxml_open_file -- Creates a DOM object from XML file
domxml_open_mem -- Creates a DOM object of an XML document
domxml_version --  Get XML library version
domxml_xmltree --  Creates a tree of PHP objects from an XML document
domxml_xslt_stylesheet_doc --  Creates a DomXsltStylesheet Object from a DomDocument Object.
domxml_xslt_stylesheet_file --  Creates a DomXsltStylesheet Object from a xsl document in a file.
domxml_xslt_stylesheet --  Creates a DomXsltStylesheet Object from a xml document in a string.
xpath_eval_expression --  Evaluates the XPath Location Path in the given string
xpath_eval --  Evaluates the XPath Location Path in the given string
xpath_new_context --  Creates new xpath context
xptr_eval --  Evaluate the XPtr Location Path in the given string
xptr_new_context --  Create new XPath Context