DOM Functions DOM
&reftitle.intro; The DOM extension is the replacement for the DOM XML extension from PHP 4. The extension still contains many old functions, but they should no longer be used. In particular, functions that are not object-oriented should be avoided. The extension allows you to operate on an XML document with the DOM API.
&reftitle.classes; The API of the module follows the DOM Level 2 standard as closely as possible. Consequently, the API is fully object-oriented. It is a good idea to have the DOM standard available when using this module. This module defines a number of classes, which are explained in the following tables. Classes with an equivalent in the DOM standard are named DOMxxx.
<classname>DOMAttr</classname> Extends DOMNode.
&reftitle.methods; isId - Checks if attribute is a defined ID
&reftitle.properties; <tgroup cols="4"> <thead> <row> <entry>Name</entry> <entry>Type</entry> <entry>Read-only</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry>name</entry> <entry>string</entry> <entry>yes</entry> <entry>The name of the attribute</entry> </row> <row> <entry>ownerElement</entry> <entry>DOMElement</entry> <entry>yes</entry> <entry>The element which contains the attribute</entry> </row> <row> <entry>schemaTypeInfo</entry> <entry>bool</entry> <entry>yes</entry> <entry>Not implemented yet, always return &true;</entry> </row> <row> <entry>specified</entry> <entry>bool</entry> <entry>yes</entry> <entry>Not implemented yet, always return &true;</entry> </row> <row> <entry>value</entry> <entry>string</entry> <entry>no</entry> <entry>The value of the attribute</entry> </row> </tbody> </tgroup> </table> </section> </section> <section id='dom.class.domcharacterdata'> <title><classname>DOMCharacterData</classname> Extends DOMNode.
&reftitle.methods; appendData - Append a string to the end of the character data of the node deleteData - Remove a range of characters from the node insertData - Insert a string at the specified 16-bit unit offset replaceData - Replace a substring within the DOMCharacterData node substringData - Extracts a range of data from the node
&reftitle.properties;
<tgroup cols="4"> <thead> <row> <entry>Name</entry> <entry>Type</entry> <entry>Read-only</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry>data</entry> <entry>string</entry> <entry>no</entry> <entry>The contents of the node</entry> </row> <row> <entry>length</entry> <entry>int</entry> <entry>yes</entry> <entry>The length of the contents</entry> </row> </tbody> </tgroup> </table> </section> </section> <section id='dom.class.domdocument'> <title><classname>DOMDocument</classname> Extends DOMNode.
&reftitle.constructor; __construct - construct a new DOMDocument object
&reftitle.methods; createAttribute - Create new attribute createAttributeNS - Create new attribute node with an associated namespace createCDATASection - Create new cdata node createComment - Create new comment node createDocumentFragment - Create new document fragment createElement - Create new element node createElementNS - Create new element node with an associated namespace createEntityReference - Create new entity reference node createProcessingInstruction - Creates new PI node createTextNode - Create new text node getElementById - Searches for an element with a certain id getElementsByTagName - Searches for all elements with given tag name getElementsByTagNameNS - Searches for all elements with given tag name in specified namespace importNode - Import node into current document load - Load XML from a file loadHTML - Load HTML from a string loadHTMLFile - Load HTML from a file loadXML - Load XML from a string normalize - Normalizes document relaxNGValidate - Performs relaxNG validation on the document relaxNGValidateSource - Performs relaxNG validation on the document save - Dumps the internal XML tree back into a file saveHTML - Dumps the internal document into a string using HTML formatting saveHTMLFile - Dumps the internal document back into a file using HTML formatting saveXML - Dumps the internal XML tree back into a string schemaValidate - Validates a document based on a schema schemaValidateSource - Validates a document based on a schema validate - Validates the document based on its DTD xinclude - Substitutes XIncludes in a DOMDocument Object
&reftitle.properties;
<tgroup cols="4"> <thead> <row> <entry>Name</entry> <entry>Type</entry> <entry>Read-only</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry>actualEncoding</entry> <entry>string</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>config</entry> <entry>DOMConfiguration</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>doctype</entry> <entry>DOMDocumentType</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>documentElement</entry> <entry>DOMElement</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>documentURI</entry> <entry>string</entry> <entry>no</entry> <entry></entry> </row> <row> <entry>encoding</entry> <entry>string</entry> <entry>no</entry> <entry></entry> </row> <row> <entry>formatOutput</entry> <entry>bool</entry> <entry>no</entry> <entry></entry> </row> <row> <entry>implementation</entry> <entry>DOMImplementation</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>preserveWhiteSpace</entry> <entry>bool</entry> <entry>no</entry> <entry>Do not remove redundant white space. Default to &true;.</entry> </row> <row> <entry>recover</entry> <entry>bool</entry> <entry>no</entry> <entry></entry> </row> <row> <entry>resolveExternals</entry> <entry>bool</entry> <entry>no</entry> <entry> Set it to &true; to load external entities from a doctype declaration. This is useful for including character entities in your XML document. </entry> </row> <row> <entry>standalone</entry> <entry>bool</entry> <entry>no</entry> <entry></entry> </row> <row> <entry>strictErrorChecking</entry> <entry>bool</entry> <entry>no</entry> <entry>Throws DOMException on errors. Default to &true;.</entry> </row> <row> <entry>substituteEntities</entry> <entry>bool</entry> <entry>no</entry> <entry></entry> </row> <row> <entry>validateOnParse</entry> <entry>bool</entry> <entry>no</entry> <entry>Loads and validates against the DTD. Default to &false;.</entry> </row> <row> <entry>version</entry> <entry>string</entry> <entry>no</entry> <entry></entry> </row> <row> <entry>xmlEncoding</entry> <entry>string</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>xmlStandalone</entry> <entry>bool</entry> <entry>no</entry> <entry></entry> </row> <row> <entry>xmlVersion</entry> <entry>string</entry> <entry>no</entry> <entry></entry> </row> </tbody> </tgroup> </table> </section> </section> <section id='dom.class.domdocumenttype'> <title><classname>DOMDocumentType</classname> Extends DOMNode
&reftitle.properties;
<tgroup cols="4"> <thead> <row> <entry>Name</entry> <entry>Type</entry> <entry>Read-only</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry>publicId</entry> <entry>string</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>systemId</entry> <entry>string</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>name</entry> <entry>string</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>entities</entry> <entry>DOMNamedNodeMap</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>notations</entry> <entry>DOMNamedNodeMap</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>internalSubset</entry> <entry>string</entry> <entry>yes</entry> <entry></entry> </row> </tbody> </tgroup> </table> </section> </section> <section id='dom.class.domelement'> <title><classname>DOMElement</classname> Extends DOMNode.
&reftitle.methods; getAttribute - Returns value of attribute getAttributeNode - Returns attribute node getAttributeNodeNS - Returns attribute node getAttributeNS - Returns value of attribute getElementsByTagName - Gets elements by tagname getElementsByTagNameNS - Get elements by namespaceURI and localName hasAttribute - Checks to see if attribute exists hasAttributeNS - Checks to see if attribute exists removeAttribute - Removes attribute removeAttributeNode - Removes attribute removeAttributeNS - Removes attribute setAttribute - Adds new attribute setAttributeNode - Adds new attribute node to element setAttributeNodeNS - Adds new attribute node to element setAttributeNS - Adds new attribute
&reftitle.properties;
<tgroup cols="4"> <thead> <row> <entry>Name</entry> <entry>Type</entry> <entry>Read-only</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry>schemaTypeInfo</entry> <entry>bool</entry> <entry>yes</entry> <entry>Not implemented yet, always return &true;</entry> </row> <row> <entry>tagName</entry> <entry>string</entry> <entry>yes</entry> <entry>The element name</entry> </row> </tbody> </tgroup> </table> </section> </section> <section id='dom.class.domentity'> <title><classname>DOMEntity</classname> Extends DOMNode
&reftitle.properties;
<tgroup cols="4"> <thead> <row> <entry>Name</entry> <entry>Type</entry> <entry>Read-only</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry>publicId</entry> <entry>string</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>systemId</entry> <entry>string</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>notationName</entry> <entry>string</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>actualEncoding</entry> <entry>string</entry> <entry>no</entry> <entry></entry> </row> <row> <entry>encoding</entry> <entry>string</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>version</entry> <entry>string</entry> <entry>no</entry> <entry></entry> </row> </tbody> </tgroup> </table> </section> </section> <section id='dom.class.domentityreference'> <title><classname>DOMEntityReference</classname> Extends DOMNode.
<classname>DOMException</classname> DOM operations raise exceptions under perticular circumstances, i.e., when an operation is impossible to perform for logical reasons. See also .
&reftitle.properties;
<tgroup cols="4"> <thead> <row> <entry>Name</entry> <entry>Type</entry> <entry>Read-only</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry>code</entry> <entry>int</entry> <entry>yes</entry> <entry>An integer indicating the type of error generated</entry> </row> </tbody> </tgroup> </table> </section> </section> <section id='dom.class.domimplementation'> <title><classname>DOMImplementation</classname> The DOMImplementation interface provides a number of methods for performing operations that are independent of any particular instance of the document object model.
&reftitle.methods; createDocument - Creates a DOM Document object of the specified type with its document element createDocumentType - Creates an empty DOMDocumentType object hasFeature - Test if the DOM implementation implements a specific feature
<classname>DOMNameList</classname>
&reftitle.methods; getName - getNamespaceURI -
&reftitle.properties;
<tgroup cols="4"> <thead> <row> <entry>Name</entry> <entry>Type</entry> <entry>Read-only</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry>length</entry> <entry>int</entry> <entry>yes</entry> <entry></entry> </row> </tbody> </tgroup> </table> </section> </section> <section id='dom.class.domnode'> <title><classname>DOMNode</classname>
&reftitle.methods; appendChild - Adds new child at the end of the children cloneNode - Clones a node hasAttributes - Checks if node has attributes hasChildNodes - Checks if node has children insertBefore - Adds new child at the end of the children isSameNode - Indicates if two nodes are the same node isSupported - Checks if feature is supported for specified version lookupNamespaceURI - Returns namespace URI of the node based on the prefix lookupPrefix - Returns name space prefix of the node based on namespaceURI normalize - Normalizes the node removeChild - Removes child from list of children replaceChild - Replaces a child
&reftitle.properties;
<tgroup cols="4"> <thead> <row> <entry>Name</entry> <entry>Type</entry> <entry>Read-only</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry>nodeName</entry> <entry>string</entry> <entry>yes</entry> <entry>Returns the more accurate name for the current node type</entry> </row> <row> <entry>nodeValue</entry> <entry>string</entry> <entry>no</entry> <entry></entry> </row> <row> <entry>nodeType</entry> <entry>int</entry> <entry>yes</entry> <entry>Gets the type of the node. One of the predefined XML_xxx_NODE constants</entry> </row> <row> <entry>parentNode</entry> <entry>DOMNode</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>childNodes</entry> <entry>DOMNodeList</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>firstChild</entry> <entry>DOMNode</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>lastChild</entry> <entry>DOMNode</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>previousSibling</entry> <entry>DOMNode</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>nextSibling</entry> <entry>DOMNode</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>attributes</entry> <entry>DomNamedNodeMap</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>ownerDocument</entry> <entry>DOMDocument</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>namespaceURI</entry> <entry>string</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>prefix</entry> <entry>string</entry> <entry>no</entry> <entry></entry> </row> <row> <entry>localName</entry> <entry>string</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>baseURI</entry> <entry>string</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>textContent</entry> <entry>string</entry> <entry>no</entry> <entry></entry> </row> </tbody> </tgroup> </table> </section> </section> <section id='dom.class.domnotation'> <title><classname>DOMNotation</classname> Extends DOMNode
&reftitle.properties;
<tgroup cols="4"> <thead> <row> <entry>Name</entry> <entry>Type</entry> <entry>Read-only</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry>publicId</entry> <entry>string</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>systemId</entry> <entry>string</entry> <entry>yes</entry> <entry></entry> </row> </tbody> </tgroup> </table> </section> </section> <section id='dom.class.domprocessinginstruction'> <title><classname>DOMProcessingInstruction</classname> Extends DOMNode.
&reftitle.properties;
<tgroup cols="4"> <thead> <row> <entry>Name</entry> <entry>Type</entry> <entry>Read-only</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry>target</entry> <entry>string</entry> <entry>yes</entry> <entry></entry> </row> <row> <entry>data</entry> <entry>string</entry> <entry>no</entry> <entry></entry> </row> </tbody> </tgroup> </table> </section> </section> <section id='dom.class.domstringlist'> <title><classname>DOMStringList</classname>
&reftitle.methods; item - Return the specified index of the collection
&reftitle.properties;
<tgroup cols="4"> <thead> <row> <entry>Name</entry> <entry>Type</entry> <entry>Read-only</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry>length</entry> <entry>int</entry> <entry>yes</entry> <entry> The number of DOMStrings in the list. Not implemented yet, always return &true;. </entry> </row> </tbody> </tgroup> </table> </section> </section> <section id='dom.class.domtext'> <title><classname>DOMText</classname>
&reftitle.methods; isElementContentWhitespace - isWhitespaceInElementContent - replaceWholeText - splitText -
&reftitle.properties;
<tgroup cols="4"> <thead> <row> <entry>Name</entry> <entry>Type</entry> <entry>Read-only</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry>wholeText</entry> <entry>string</entry> <entry>yes</entry> <entry></entry> </row> </tbody> </tgroup> </table> </section> </section> <section id='dom.class.domxpath'> <title><classname>DOMXPath</classname>
&reftitle.constructor; __construct - construct a new DOMXPath object
&reftitle.methods; registerNamespace - Registers the namespace with the DOMXpath object evaluate - Evaluates the given XPath expression and returns a typed result query - Evaluates the given XPath expression
&reftitle.properties;
<tgroup cols="4"> <thead> <row> <entry>Name</entry> <entry>Type</entry> <entry>Read-only</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry>document</entry> <entry>DOMDocument</entry> <entry></entry> <entry></entry> </row> </tbody> </tgroup> </table> </section> </section> </section> <section id="dom.examples"> &reftitle.examples; <para> Many examples in this reference require an XML file. We will use the <filename>book.xml</filename> that contains the following: </para> <para> <example> <title>chapter.xml My lists My books Title Author Language ISBN The Grapes of Wrath John Steinbeck en 0140186409 The Pearl John Steinbeck en 014017737X Samarcande Amine Maalouf fr 2253051209 ]]> &reference.dom.constants; &reference.dom.functions;