DOM FunctionsDOM
&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.
DOMAttr
Extends DOMNode.
&reftitle.methods;
isId - Checks if attribute is a defined ID
&reftitle.properties;
NameTypeRead-onlyDescriptionnamestringyesThe name of the attributeownerElementDOMElementyesThe element which contains the attributeschemaTypeInfoboolyesNot implemented yet, always return &true;specifiedboolyesNot implemented yet, always return &true;valuestringnoThe value of the attribute
DOMCharacterData
Extends DOMNode.
&reftitle.methods;
appendData - Append a string to the end of the character data of the nodedeleteData - Remove a range of characters from the nodeinsertData - Insert a string at the specified 16-bit unit offsetreplaceData - Replace a substring within the DOMCharacterData nodesubstringData - Extracts a range of data from the node
&reftitle.properties;
NameTypeRead-onlyDescriptiondatastringnoThe contents of the nodelengthintyesThe length of the contents
DOMDocument
Extends DOMNode.
&reftitle.constructor;
__construct - construct a new DOMDocument object
&reftitle.methods;
createAttribute - Create new attributecreateAttributeNS - Create new attribute node with an associated namespacecreateCDATASection - Create new cdata nodecreateComment - Create new comment nodecreateDocumentFragment - Create new document fragmentcreateElement - Create new element nodecreateElementNS - Create new element node with an associated namespacecreateEntityReference - Create new entity reference nodecreateProcessingInstruction - Creates new PI nodecreateTextNode - Create new text nodegetElementById - Searches for an element with a certain idgetElementsByTagName - Searches for all elements with given tag namegetElementsByTagNameNS - Searches for all elements with given tag name in specified namespaceimportNode - Import node into current documentload - Load XML from a fileloadHTML - Load HTML from a stringloadHTMLFile - Load HTML from a fileloadXML - Load XML from a stringnormalize - Normalizes documentrelaxNGValidate - Performs relaxNG validation on the documentrelaxNGValidateSource - Performs relaxNG validation on the documentsave - Dumps the internal XML tree back into a filesaveHTML - Dumps the internal document into a string using HTML formattingsaveHTMLFile - Dumps the internal document back into a file using HTML formattingsaveXML - Dumps the internal XML tree back into a stringschemaValidate - Validates a document based on a schemaschemaValidateSource - Validates a document based on a schemavalidate - Validates the document based on its DTDxinclude - Substitutes XIncludes in a DOMDocument Object
&reftitle.properties;
NameTypeRead-onlyDescriptionactualEncodingstringyesconfigDOMConfigurationyesdoctypeDOMDocumentTypeyesdocumentElementDOMElementyesdocumentURIstringnoencodingstringnoformatOutputboolnoimplementationDOMImplementationyespreserveWhiteSpaceboolnoDo not remove redundant white space. Default to &true;.recoverboolnoresolveExternalsboolno
Set it to &true; to load external entities from a doctype
declaration. This is useful for including character entities in
your XML document.
standaloneboolnostrictErrorCheckingboolnoThrows DOMException on errors. Default to &true;.substituteEntitiesboolnovalidateOnParseboolnoLoads and validates against the DTD. Default to &false;.versionstringnoxmlEncodingstringyesxmlStandaloneboolnoxmlVersionstringno
DOMElement
Extends DOMNode.
&reftitle.methods;
getAttribute - Returns value of attributegetAttributeNode - Returns attribute nodegetAttributeNodeNS - Returns attribute nodegetAttributeNS - Returns value of attributegetElementsByTagName - Gets elements by tagnamegetElementsByTagNameNS - Get elements by namespaceURI and localNamehasAttribute - Checks to see if attribute existshasAttributeNS - Checks to see if attribute existsremoveAttribute - Removes attributeremoveAttributeNode - Removes attributeremoveAttributeNS - Removes attributesetAttribute - Adds new attributesetAttributeNode - Adds new attribute node to elementsetAttributeNodeNS - Adds new attribute node to elementsetAttributeNS - Adds new attribute
&reftitle.properties;
NameTypeRead-onlyDescriptionschemaTypeInfoboolyesNot implemented yet, always return &true;tagNamestringyesThe element name
DOMEntityReference
Extends DOMNode.
DOMException
DOM operations raise exceptions under perticular circumstances, i.e.,
when an operation is impossible to perform for logical reasons.
See also .
&reftitle.properties;
NameTypeRead-onlyDescriptioncodeintyesAn integer indicating the type of error generated
DOMImplementation
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 elementcreateDocumentType - Creates an empty DOMDocumentType objecthasFeature - Test if the DOM implementation implements a specific featureDOMNameList
&reftitle.methods;
getName - getNamespaceURI -
&reftitle.properties;
NameTypeRead-onlyDescriptionlengthintyes
DOMNode
&reftitle.methods;
appendChild - Adds new child at the end of the childrencloneNode - Clones a nodehasAttributes - Checks if node has attributeshasChildNodes - Checks if node has childreninsertBefore - Adds new child at the end of the childrenisSameNode - Indicates if two nodes are the same nodeisSupported - Checks if feature is supported for specified versionlookupNamespaceURI - Returns namespace URI of the node based on the prefixlookupPrefix - Returns name space prefix of the node based on namespaceURInormalize - Normalizes the noderemoveChild - Removes child from list of childrenreplaceChild - Replaces a child
&reftitle.properties;
NameTypeRead-onlyDescriptionnodeNamestringyesReturns the more accurate name for the current node typenodeValuestringnonodeTypeintyesGets the type of the node. One of the predefined XML_xxx_NODE constantsparentNodeDOMNodeyeschildNodesDOMNodeListyesfirstChildDOMNodeyeslastChildDOMNodeyespreviousSiblingDOMNodeyesnextSiblingDOMNodeyesattributesDomNamedNodeMapyesownerDocumentDOMDocumentyesnamespaceURIstringyesprefixstringnolocalNamestringyesbaseURIstringyestextContentstringno
DOMXPath
&reftitle.constructor;
__construct - construct a new DOMXPath object
&reftitle.methods;
registerNamespace - Registers the namespace with the DOMXpath objectevaluate - Evaluates the given XPath expression and returns a typed resultquery - Evaluates the given XPath expression
&reftitle.properties;
NameTypeRead-onlyDescriptiondocumentDOMDocument
&reftitle.examples;
Many examples in this reference require an XML file. We will use the
book.xml that contains the following:
chapter.xmlMy listsMy booksTitleAuthorLanguageISBNThe Grapes of WrathJohn Steinbecken0140186409The PearlJohn Steinbecken014017737XSamarcandeAmine Maalouffr2253051209
]]>
&reference.dom.constants;
&reference.dom.functions;