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.install;
&no.install;
&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. The DOMAttr
interface represents an attribute in an DOMElement object.
&reftitle.constructor;
- construct a new DOMAttr object
&reftitle.methods;
- Checks if attribute is a defined ID
&reftitle.properties;
NameTypeRead-onlyDescriptionnamestringyesThe name of the attributeownerElementDOMElementyesThe element which contains the attributeschemaTypeInfoboolyesNot implemented yet, always return &null;specifiedboolyesNot implemented yet, always return &null;valuestringnoThe value of the attribute
DOMCharacterData
Extends DOMNode.
&reftitle.methods;
- Append a string to the end of the character data of the node - Remove a range of characters from the node - Insert a string at the specified 16-bit unit offset - Replace a substring within the DOMCharacterData node - Extracts a range of data from the node
&reftitle.properties;
NameTypeRead-onlyDescriptiondatastringnoThe contents of the nodelengthintyesThe length of the contents
DOMComment
Extends DOMCharacterData.
&reftitle.constructor;
- construct a new DOMComment objectDOMDocument
Extends DOMNode.
&reftitle.constructor;
- construct a new DOMDocument object
&reftitle.methods;
- Create new attribute - Create new attribute node with an associated namespace - Create new cdata node - Create new comment node - Create new document fragment - Create new element node - Create new element node with an associated namespace - Create new entity reference node - Creates new PI node - Create new text node - Searches for an element with a certain id - Searches for all elements with given tag name - Searches for all elements with given tag name in specified namespace - Import node into current document - Load XML from a file - Load HTML from a string - Load HTML from a file - Load XML from a string - Normalizes document - Performs relaxNG validation on the document - Performs relaxNG validation on the document - Dumps the internal XML tree back into a file - Dumps the internal document into a string using HTML formatting - Dumps the internal document back into a file using HTML formatting - Dumps the internal XML tree back into a string - Validates a document based on a schema - Validates a document based on a schema - Validates the document based on its DTD - Substitutes XIncludes in a DOMDocument Object
&reftitle.properties;
NameTypeRead-onlyDescriptionactualEncodingstringyesconfigDOMConfigurationyesdoctypeDOMDocumentTypeyes
The Document Type Declaration associated with this document.
documentElementDOMElementyes
This is a convenience attribute that allows direct access to the
child node that is the document element of the document.
documentURIstringno
The location of the document or &null; if undefined.
encodingstringnoformatOutputboolnoimplementationDOMImplementationyes
The DOMImplementation object that handles
this document.
preserveWhiteSpaceboolnoDo 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;.versionstringnoxmlEncodingstringyes
An attribute specifying, as part of the XML declaration, the
encoding of this document. This is &null; when unspecified or when it
is not known, such as when the Document was created in memory.
xmlStandaloneboolno
An attribute specifying, as part of the XML declaration, whether
this document is standalone. This is &false; when unspecified.
xmlVersionstringno
An attribute specifying, as part of the XML declaration, the
version number of this document. If there is no declaration and if
this document supports the "XML" feature, the value is "1.0".
DOMDocumentType
Extends DOMNode
Each DOMDocument has a
doctype attribute whose value is either &null; or a
DOMDocumentType object.
&reftitle.properties;
NameTypeRead-onlyDescriptionpublicIdstringyesThe public identifier of the external subset.systemIdstringyesThe system identifier of the external subset. This may be an
absolute URI or not.namestringyesThe name of DTD; i.e., the name immediately following the
DOCTYPE keyword.entitiesDOMNamedNodeMapyes
A DOMNamedNodeMap containing the general
entities, both external and internal, declared in the DTD.
notationsDOMNamedNodeMapyes
A DOMNamedNodeMap containing the notations
declared in the DTD.
internalSubsetstringyes
The internal subset as a string, or null if there is none. This is
does not contain the delimiting square brackets.
DOMElement
Extends DOMNode.
&reftitle.constructor;
- construct a new DOMElement object
&reftitle.methods;
- Returns value of attribute - Returns attribute node - Returns attribute node - Returns value of attribute - Gets elements by tagname - Get elements by namespaceURI and localName - Checks to see if attribute exists - Checks to see if attribute exists - Removes attribute - Removes attribute - Removes attribute - Adds new attribute - Adds new attribute node to element - Adds new attribute node to element - Adds new attribute
&reftitle.properties;
NameTypeRead-onlyDescriptionschemaTypeInfoboolyesNot implemented yet, always return &null;tagNamestringyesThe element name
DOMEntity
Extends DOMNode
This interface represents a known entity, either parsed or unparsed, in
an XML document.
&reftitle.properties;
NameTypeRead-onlyDescriptionpublicIdstringyes
The public identifier associated with the entity if specified, and
&null; otherwise.
systemIdstringyes
The system identifier associated with the entity if specified, and
&null; otherwise. This may be an absolute URI or not.
notationNamestringyes
For unparsed entities, the name of the notation for the entity. For
parsed entities, this is &null;.
actualEncodingstringno
An attribute specifying the encoding used for this entity at the
time of parsing, when it is an external parsed entity. This is
&null; if it an entity from the internal subset or if it is not
known.
encodingstringyes
An attribute specifying, as part of the text declaration, the
encoding of this entity, when it is an external parsed entity. This
is &null; otherwise.
versionstringyes
An attribute specifying, as part of the text declaration, the
version number of this entity, when it is an external parsed
entity. This is &null; otherwise.
DOMEntityReference
Extends DOMNode.
&reftitle.constructor;
- construct a new DOMEntityReference objectDOMException
DOM operations raise exceptions under particular 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.constructor;
- construct a new DOMImplementation object
&reftitle.methods;
- Creates a DOM Document object of the specified type with its document element - Creates an empty DOMDocumentType object - Test if the DOM implementation implements a specific featureDOMNode
&reftitle.methods;
- Adds new child at the end of the children - Clones a node - Checks if node has attributes - Checks if node has children - Adds a
new child before a reference node - Indicates if two nodes are the same node - Checks if feature is supported for specified version - Returns namespace URI of the node based on the prefix - Returns name space prefix of the node based on namespaceURI - Normalizes the node - Removes child from list of children - Replaces a child
&reftitle.properties;
NameTypeRead-onlyDescriptionnodeNamestringyesReturns the most accurate name for the current node typenodeValuestringnoThe value of this node, depending on its type.nodeTypeintyesGets the type of the node. One of the predefined XML_xxx_NODE constantsparentNodeDOMNodeyesThe parent of this node.childNodesDOMNodeListyes
A DOMNodeList that contains all children of
this node. If there are no children, this is an empty
DOMNodeList.
firstChildDOMNodeyes
The first child of this node. If there is no such node, this
returns &null;.
lastChildDOMNodeyes
The last child of this node. If there is no such node, this returns
&null;.
previousSiblingDOMNodeyes
The node immediately preceding this node. If there is no such node,
this returns &null;.
nextSiblingDOMNodeyes
The node immediately following this node. If there is no such node,
this returns &null;.
attributesDOMNamedNodeMapyes
A DOMNamedNodeMap containing the attributes
of this node (if it is a DOMElement) or
&null; otherwise.
ownerDocumentDOMDocumentyes
The DOMDocument object associated with this
node.
namespaceURIstringyes
The namespace URI of this node, or &null; if it is unspecified.
prefixstringno
The namespace prefix of this node, or &null; if it is unspecified.
localNamestringyes
Returns the local part of the qualified name of this node.
baseURIstringyes
The absolute base URI of this node or &null; if the implementation
wasn't able to obtain an absolute URI.
textContentstringno
This attribute returns the text content of this node and its
descendants.
DOMNodeList
&reftitle.methods;
- Retrieves a node specified by index
&reftitle.properties;
NameTypeRead-onlyDescriptionlengthintyes
The number of nodes in the list. The range of valid child node
indices is 0 to length - 1 inclusive.
DOMText
Extends DOMCharacterData.
&reftitle.constructor;
- construct a new DOMText object
&reftitle.methods;
- Indicates whether this text node contains whitespace - Breaks the node into two nodes at the specified offset
&reftitle.properties;
NameTypeRead-onlyDescriptionwholeTextstringyes
DOMXPath
&reftitle.constructor;
- construct a new DOMXPath object
&reftitle.methods;
- Registers the namespace with the DOMXpath object - Evaluates the given XPath expression and returns a typed result if possible - Evaluates the given XPath expression
&reftitle.properties;
NameTypeRead-onlyDescriptiondocumentDOMDocument
&reftitle.examples;
Many examples in this reference require an XML file. We will use
book.xml that contains the following:
chapter.xmlMy listsMy booksTitleAuthorLanguageISBNThe Grapes of WrathJohn Steinbecken0140186409The PearlJohn Steinbecken014017737XSamarcandeAmine Maalouffr2253051209
]]>
&reference.dom.constants;
&reference.dom.functions;