Class DOMIT_Element
A class representing the DOM Element.

isPublic? yes
isAbstract? no

Inheritance tree:


DOMIT_Node
|
DOMIT_ChildNodes_Interface
|
DOMIT_Element

Known subclasses:

None

Source file: xml_domit_parser.php




Constructor
Initializes DOMIT_Element variables and those of the superclass.

Signature: &DOMIT_Element($tagName)

isPublic? no




Public Constants



Private Constants



Public Fields
nodeName
The name of the current node. For DOMIT_Element,the name of the tag.

Type: String

nodeValue
The value of the current node. Null for DOMIT_Element.

Type: String

nodeType
An integer representing the type of the current node. For DOMIT_Element, nodeType is 1.

Type: int

parentNode
A reference to the node of which the current node is a child.

Type: DOMIT_Node

childNodes
An array of node references of which the current node is parent. Null if the current node has no children.

Type: array

firstChild
A reference to the first node in the childNodes list. Null if the current node has no children.

Type: DOMIT_Node

lastChild
A reference to the last node in the childNodes list. Null if the current node has no children.

Type: DOMIT_Node

previousSibling
A reference to the node prior to the current node in the childNodes list. Null if the current node is the first child.

Type: DOMIT_Node

nextSibling
A reference to the node after the current node in the childNodes list. Null if the current node is the last child.

Type: DOMIT_Node

attributes
A list of attributes for the current element (in DOMIT! Lite this is an associative array).

Type: DOMIT_NamedNodeMap_Attr

ownerDocument
A reference to the DOMIT_Document. Null if the node has not yet been added to the document.

Type: DOMIT_Document




Private Fields
uid
A unique id assigned to each node. Note that this id is non-persistent.

Type: int




Public Methods
appendChild
Adds the specified node as a child of the current DOMIT_Element.

Signature: appendChild(&$child)

Parameters:

DOMIT_Element child - The node that is to be appended.

Returns:

DOMIT_Element - The appended DOMIT_Elementnode.

Example:

A child node is appended to the $myElement node:

$myElement->appendChild($elementNode);

insertBefore
Inserts node $newChild before $refChild in the childNodes of $this. If $refChild does not exist, $newChild is appended to the node chain.

Signature: &insertBefore(&$newChild, &$refChild)

Parameters:

DOMIT_Node newChild - The new node to be added

DOMIT_Node refChild - The existing node before which the new node will be added

Returns:

DOMIT_Node - A reference to the new node being added.

Example:

The following example inserts a "Book" node named $goodNovel before another named $okNovel in a childNodes list named $bestSellers.

$bestSellers->insertBefore($goodNovel, $okNovel);

replaceChild
Replaces node $oldChild with $newChild.

Signature: replaceChild(&$newChild, &$oldChild)

Parameters:

DOMIT_Node newChild - The new node that is to replace the old node.

DOMIT_Node oldChild - The old node that is to be replaced by the new node.

Returns:

DOMIT_Node - The new node $newChild, or false if $oldChild does not exist.

Example:

An old $userProfile node is replaced by a new node:

$userProfile->replaceChild($newProfile, $oldProfile);

removeChild
Removes the specified node from the document.

Signature: &removeChild(&$oldChild)

Parameters:

DOMIT_Node oldChild - The node that is to be removed.

Returns:

DOMIT_Node - The deleted node $oldChild, or false if $oldChild does not exist.

Example:

Node $unpopularNovel is removed from the $bestSellers parent node.

$bestSellers->removeNode($unpopularNovel);

getTagName
Returns the name of the element tag.

Signature: getTagName()

Returns:

String - The name of the element tag.

Example:

The tag name is returned.

$tagName = $myElement->getTagName();

cloneNode
Returns a copy of the specified node, and if $deep is set to true, all nodes below it in the hierarchy.

Signature: &cloneNode($deep)

Parameters:

boolean deep - True if the children below the cloned node are also to be cloned.

Returns:

DOMIT_Node - The cloned node, with a clone of all subnodes if $deep is set to true.

Example:

In the following example, a node named $styleTemplate is cloned, presumably so the user can create a new style based on the characteristics of the original node.

$newStyle =& styleTemplate->cloneNode(false);

getText
Returns the text contained in all DOMIT_TextNodes and DOMIT_CDataSections that are children of the specified starting node

Signature: getText()

Example:

All text and cdata nodes in the document will be concatenated and returned.

$allDocmentText = $xmldoc->getText();

setText
If a child text node exists, sets the nodeValue to $data. A child text node is created if none exists

Signature: setText($data)

Parameters:

string data - The text data of the node.

Example:

A child text node is added if none exists and the data added as its nodeValue.

$someElement->setText('This is some data');

getElementsByTagName
Returns a NodeList of DOMIT_Elements with the specified nodeName.

Signature: &getElementsByTagName($tagName)

Parameters:

String tagName - The nodeName for which to search.

Returns:

DOMIT_NodeList - The list of found nodes.

Example:

All child Elements named "book" will be returned.

$bookCollection =& $libraryElement->getElementsByTagName("book");

getElementsByTagNameNS
Retrieves a NodeList of child elements with the specified namespaceURI and localName.

Signature: &getElementsByTagNameNS($namespaceURI, $localName)

Parameters:

String namespaceURI - The matching namespaceURI, or "*" if all elements are to be returned.

String localName - The matching localName, or "*" if all elements are to be returned.

Returns:

DOMIT_NodeList - The DOMIT_NodeList of found DOMIT_Elements.

Example:

A DOMIT_NodeList of matching elements is returned:

$authors =& $library->getElementsByTagNameNS("http://purl.org/dc/elements/1.1", "creator");

getElementsByPath
Retrieves an element or DOMIT_NodeList of elements corresponding to the specified "path"-like expression. Relative paths (which do not start with "/"), absolute paths (which start with "/") , and variable paths (which start with "//") are allowed. For more information, please see the DOMIT! Tutorial. For more complex patterns, please see the selectNodes method.

Signature: &getElementsByPath($pattern, $nodeIndex = 0)

Parameters:

String pattern - The path-like pattern specifying the elements(s) to be returned.

int nodeIndex - If more than one element matches the specified pattern, setting nodeIndex will return a single node from these possibilities. This is a one-based index.

Returns:

Domit_Node - A DOMIT_NodeList of DOMIT_Nodes, or a single DOMIT_Node, described by the expression.

Example:

The first "param" element found with a parent named "params" is returned:

$myNode =& $xmlDoc->getElementsByPath("//params/param", 1);

getAttribute
Returns the value of attribute with the specified name.

Signature: getAttribute($name)

Parameters:

String name - The name of the attribute whose value is to be retrieved.

Returns:

String - The value of the name attribute, or an empty string if the attribute is not found.

Example:

The value of the attribute name "myatt" is returned.

$attValue = $anElement->getAttribute("myatt");

getAttributeNS
Gets the value of the attribute with the specified namespaceURI and localName, if it exists.

Signature: getAttributeNS($namespaceURI, $localName)

Parameters:

String namespaceURI - The namespaceURI of the attribute.

String localName - The localName of the attribute.

Returns:

String - The value of the attribute, or an empty string if the attribute is not found.

Example:

The value of the attribute named "author" in the namespace "http://www.engageinteractive.com" is returned.

$attValue = $anElement->getAttributeNS("http://www.engageinteractive.com", "author");

setAttribute
Sets the value of the named attribute.

Signature: setAttribute($name, $value)

Parameters:

String name - The name of the attribute whose value is to be set.

String value - The value to which the named attribute should be set.

Example:

The value of the attribute named "myatt" is set to "10".

$anElement->setAttribute("myatt", "10");

setAttributeNS
Sets the value of the specified attribute; creates a new attribute if one doesn't exist.

Signature: setAttributeNS($namespaceURI, $qualifiedName, $value)

Parameters:

String namespaceURI - The namespaceURI of the attribute whose value is to be set.

String qualifiedName - The qualifiedName of the attribute whose value is to be set.

String value - The value to which the named attribute should be set.

Example:

The value of the attribute named "ei:author" is set to "10".

$anElement->setAttributeNS("http://www.engageinteractive.com", "ei:author", "10");

removeAttribute
Removes the named attribute if it exists.

Signature: removeAttribute($name)

Parameters:

String name - The name of the attribute to be removed.

Example:

The attribute named "myatt" is removed.

$anElement->removeAttribute("myatt");

removeAttributeNS
Removes the specified attribute if it exists.

Signature: removeAttributeNS($namespaceURI, $localName)

Parameters:

String namespaceURI - The namespaceURI of the attribute to be removed.

String localName - The localName of the attribute to be removed.

Example:

The attribute named "author" in the namespace "http://www.engageinteractive.com" is removed.

$anElement->removeAttributeNS("http://www.engageinteractive.com", "author");

hasAttribute
Tests whether an attribute with the specified name exists.

Signature: hasAttribute($name)

Parameters:

String name - The name of the attribute to test for.

Returns:

boolean - True if the attribute exists, false if it does not.

Example:

True is returned if the element has an attribute named "myatt".

$exists = $anElement->hasAttribute("myatt");

hasAttributeNS
Determines whether an attribute with the specified namespaceURI and localName exists.

Signature: hasAttributeNS($namespaceURI, $localName)

Parameters:

String namespaceURI - The namespaceURI of the attribute to test for.

String localName - The localName of the attribute to test for.

Returns:

boolean - True if the attribute exists, false if it does not.

Example:

True is returned if the element has an attribute named "author" in the namespace "http://www.engageinteractive.com".

$exists = $anElement->hasAttributeNS("http://www.engageinteractive.com", "author");

getAttributeNode
Returns the attribute node with the specified name (not present in DOMIT! Lite).

Signature: &getAttributeNode($name)

Parameters:

String name - The name of the attribute to be retrieved.

Returns:

DOMIT_Attr - The found attribute, or null if the attribute is not found.

Example:

The attribute named "myatt" is returned.

$attr =& $anElement->getAttributeNode("myatt");

getAttributeNodeNS
Gets a reference to the specified attribute node (not present in DOMIT! Lite).

Signature: &getAttributeNodeNS($namespaceURI, $localName)

Parameters:

String namespaceURI - The namespaceURI of the attribute to be retrieved.

String localName - The localName of the attribute to be retrieved.

Returns:

DOMIT_Attr - The found attribute, or null if the attribute is not found.

Example:

The attribute node named "author" in the namespace "http://www.engageinteractive.com" is returned.

$attr =& $anElement->getAttributeNodeNS("http://www.engageinteractive.com", "author");

setAttributeNode
Adds the specified attribute node to the attributes list (not present in DOMIT! Lite).

Signature: &setAttributeNode(&$newAttr)

Parameters:

DOMIT_Attr newAttr - The DOMIT_Attr node to be added to the attributes list.

Returns:

DOMIT_Attr - The found attribute, or null if the attribute is not found.

Example:

The specified attribute node is added to the attributes list.

$anElement->setAttributeNode($anAttr);

setAttributeNodeNS
Adds an attribute node to the current element (namespace aware) (not present in DOMIT! Lite).

Signature: &setAttributeNodeNS(&$newAttr)

Parameters:

DOMIT_Attr newAttr - The DOMIT_Attr node to be added to the attributes list.

Returns:

DOMIT_Attr - The found attribute, or null if the attribute is not found.

Example:

The specified attribute node is added to the attributes list.

$anElement->setAttributeNodeNS($anAttr);

removeAttributeNode
Removes the specified attribute node if it exists (not present in DOMIT! Lite).

Signature: &removeAttributeNode(&$oldAttr)

Parameters:

DOMIT_Attr oldAttr - The DOMIT_Attr node to be removed.

Returns:

DOMIT_Attr - The found attribute node, or null if the attribute is not found.

Example:

The attribute is removed.

$anElement->removeAttribute($anAttr);

normalize
Collapses all adjacent DOMIT_TextNode or DOMIT_CDATASection nodes in the element subtree.

Signature: normalize()

Example:

All adjacent text nodes in the subtree of $anElement are collapsed:

$anElement->normalize();

toArray
Returns an array representation of the element.

Signature: toArray()

Returns:

array - An array representing the element.

Example:

Prints out an array representing the specified element.

print_r($anElement->toArray());

toString
Generates an unformatted (single line, no whitespace) string representation of the element and all children.

Signature: toString($htmlSafe = false, $subEntities=false)

Parameters:

boolean htmlSafe - If true, returns an html formatted representation of the string.

boolean subEntities - True if illegal xml characters in text nodes and attributes should be converted to entities.

Returns:

String - An unformatted (single line, no whitespace) string representation of the element and all children.

Example:

An unformatted string representation of the element will be printed here:

echo ($myElement->toString(true);




Private Methods
_getElementByID
Returns the attribute node whose ID is given by elementId.

Signature: &_getElementByID($elementID, $isStrict = true)

Parameters:

String elementID - The id of the matching element.

boolean isStrict - True if XML spec is to be strictly adhered to (only attributes xml:id are considered valid).

Returns:

DOMIT_Attr - An attribute matching the query.

getTypedNodes
Adds to the NodeList any child nodes of the specified nodeType (not present in DOMIT! Lite).

Signature: getTypedNodes(&$nodeList, $type)

Parameters:

DOMIT_NodeList nodeList - The list of found nodes.

String type - The nodeType for which to search.

getValuedNodes
Adds to the NodeList any child nodes of the specified nodeValue (not present in DOMIT! Lite.

Signature: getValuedNodes(&$nodeList, $value)

Parameters:

DOMIT_NodeList nodeList - The list of found nodes.

String value - The nodeValue for which to search.


Documentation generated by ClassyDoc, using the DOMIT! and SAXY parsers.
Please visit Engage Interactive to download free copies.