eZPublish  3.8
eZDOMNode Class Reference

eZDOMNode encapsulates XML DOM nodes More...

Public Member Functions

 append_child (&$node)
 
 appendAttribute (&$node)
 
 appendAttributes ($attributeValues, $attributeDefinitions, $includeEmptyValues=false)
 
 appendChild (&$node)
 
 attributeCount ()
 
attributes ()
 
attributesNS ($namespaceURI)
 
 attributeValue ($attributeName)
 
 attributeValueNS ($attributeName, $namespaceURI)
 
 attributeValues ($attributeDefinitions=false, $defaultValue=null)
 
children ()
 
 childrenCount ()
 
 cleanup (&$node)
 
 clone ()
 
 collectTextContent (&$element)
 
content ()
 
 debugNode (&$node, $showAttributes, $showParent)
 
 dump_mem ($format, $charset=false)
 
 elementAttributeValueByName ($name, $attributeName)
 
elementByAttributeValue ($attr, $value)
 
elementByName ($name)
 
elementChildrenByName ($name)
 
elementFirstChildByName ($name)
 
elementsByName ($name)
 
elementsTextContentByName ($name)
 
 elementTextContentByName ($name)
 
 eZDOMNode ()
 
 first_child ()
 
firstChild ()
 
 get_attribute ($attributeName)
 
 get_elements_by_tagname ($name)
 
 getAttribute ($attributeName)
 
 getAttributeNS ($namespaceURI, $localName)
 
 hasAttributes ()
 
 hasChildNodes ()
 
 hasChildren ()
 
 insertBefore (&$newNode, &$refNode)
 
lastChild ()
 
 localName ()
 
 name ()
 
 namespaceURI ()
 
nextSibling ()
 
 node_value ()
 
 prefix ()
 
previousSibling ()
 
 remove_attribute ($name)
 
 removeAttribute ($name)
 
 removeAttributeNS ($namespaceURI, $localName)
 
 removeAttributes ()
 
 removeChild (&$childToRemove)
 
 removeChildren ()
 
 removeLastChild ()
 
 removeNamedAttribute ($name)
 
 removeNamedChildren ($name)
 
 replaceChild (&$newChild, &$oldChild)
 
 set_attribute ($name, $value)
 
 setAttribute ($name, $value)
 
 setAttributeNS ($namespaceURI, $qualifiedName, $value)
 
 setContent ($content)
 
 setName ($name)
 
 setNamespaceURI ($uri)
 
 setPrefix ($value)
 
 setType ($type)
 
 textContent ()
 
 toString ($level, $charset=false, $convertSpecialChars=true)
 
 type ()
 
 writeDebug (&$node, $text, $showAttributes=false, $showParent=false)
 
 writeDebugStr (&$node, $text)
 

Private Attributes

 $Attributes = array()
 Attributes. More...
 
 $Children = array()
 Subnodes. More...
 
 $content = ""
 Content of the node. More...
 
 $Content = ""
 
 $flag = false
 
 $LocalName = false
 The local part of a name. E.g: book:title, title is the local part. More...
 
 $Name = false
 Name of the node. More...
 
 $NamespaceURI = false
 Contains the namespace URI. E.g. xmlns="http://ez.no/article/", http://ez.no/article/ would be the namespace URI. More...
 
 $nodeName = null
 DOM W3C compatibility. More...
 
 $parentNode = false
 Reference to the parent node. More...
 
 $Prefix = false
 contains the namespace prefix. E.g: book:title, book is the prefix More...
 
 $tagname = null
 tagname, added for DOM XML compatibility. More...
 
 $type
 Type of the DOM node. ElementNode=1, AttributeNode=2, TextNode=3, CDATASectionNode=4. More...
 
 $Type = EZ_XML_NODE_ELEMENT
 
 $value = ''
 

Detailed Description

eZDOMNode encapsulates XML DOM nodes

The following node types are supported:

  • Element node, has value 1
  • Attribute node, has value 2
  • Text node, has value 3
  • CDATA node, has value 4
See Also
eZXML eZDOMDocument

Member Function Documentation

eZDOMNode::append_child ( $node)

Alias for libXML compatibility

eZDOMNode::appendAttribute ( $node)

Appends the attribute node $node as an attribute of the current node.

Returns
The attribute node that was just inserted or false if it failed to insert an attribute.
Note
This will only make sense for element nodes.

Referenced by set_attribute(), setAttribute(), and setAttributeNS().

eZDOMNode::appendAttributes (   $attributeValues,
  $attributeDefinitions,
  $includeEmptyValues = false 
)

Appends multiple attributes and attribute values.

Parameters
$attributeValuesAn associative array containing the attribute values to insert, it maps from lookup name to attribute value.
$attributeDefinitionsAn associative array defining how lookup names maps to attribute names, the array key is the attribute name and the array value the lookup name.
$includeEmptyValuesIf true it will set attribute values even though they don't exist in $attributeValues
$definition = array( 'name' => 'song_name',
'track' => 'track_name' );
$values = array( 'song_name' => 'Shine On You Crazy Diamond',
'track_number' => '1' );
$node->appendAttributes( $values, $definition );
\encode
The node will then look like.
\code
<song name="Shine On You Crazy Diamond" track="1" />

This method and attributeValues() work together, the returned result of attributeValues() can be inserted with this method.

Note
This will only make sense for element nodes.
See Also
attributeValues
eZDOMNode::appendChild ( $node)

Appends the node $node as a child of the current node.

Returns
The node that was just inserted or false if it failed to insert a node.
Note
This will only make sense for element nodes.

Referenced by append_child().

eZDOMNode::attributeCount ( )
Returns
The number of attributes for the node.
Note
This will only make sense for element nodes.
& eZDOMNode::attributes ( )
Returns
An array with attribute nodes.
Note
This will only make sense for element nodes.
& eZDOMNode::attributesNS (   $namespaceURI)
Returns
An array with attribute nodes matching the namespace URI $namespaceURI.
Note
This will only make sense for element nodes.
eZDOMNode::attributeValue (   $attributeName)
Deprecated:
This function is deprecated. Use getAttribute instead.
Returns
The value of the attribute named $attributeName. If no value is found false is returned.
Note
This will only make sense for element nodes.

Referenced by get_attribute().

eZDOMNode::attributeValueNS (   $attributeName,
  $namespaceURI 
)
Deprecated:
This function is deprecated. Use getAttributeNS instead.
Returns
The value of the attribute named $attributeName and having namespace $namespaceURI. If no value is found false is returned.
Note
This will only make sense for element nodes.
eZDOMNode::attributeValues (   $attributeDefinitions = false,
  $defaultValue = null 
)

Goes trough all attributes of the node and matches the attribute names with the parameter $attributeDefinitions.

Parameters
$attributeDefinitionsAn associative array which maps from matching attribute name to lookup name.
$defaultValueIf other value than null it will be set as value for all lookup names that didn't match

The matching attribute name in the will be matched against the attributes of the node. When a match is found the attribute value will be fetched and placed in the returned associative array using lookup name as key.

A code example will explain this, the variable $songNode contains the following xml

<song name="Shine On You Crazy Diamond" track="1" />

The PHP code is.

$def = array( 'name' => 'song_name',
'track' => 'track_number' );
$values = $songNode->attributeValues( $def );
\encode
\a $values will now contain.
\code
array( 'song_name' => 'Shine On You Crazy Diamond',
'track_number => '1' )

This method and appendAttributes() work together, the values inserted with appendAttributes() can be extracted with this method.

Note
This will only make sense for element nodes.
See Also
elementAttributeValueByName, appendAttributes
& eZDOMNode::children ( )
Returns
An array with child nodes.
Note
This will only make sense for element nodes.
eZDOMNode::childrenCount ( )
Returns
The number of children for the node.
Note
This will only make sense for element nodes.
eZDOMNode::cleanup ( $node)

Subtree destructor. Needed to clean memory properly.

Referenced by eZDOMDocument\cleanup().

eZDOMNode::clone ( )

Makes a copy of the current node and returns a reference to it.

eZDOMNode::collectTextContent ( $element)

Referenced by textContent().

& eZDOMNode::content ( )
Returns
The content of the node or false if it does not contain any content.
Note
This will only make sense for text and CDATA nodes.

Referenced by eZDOMNode().

eZDOMNode::debugNode ( $node,
  $showAttributes,
  $showParent 
)

Referenced by writeDebug().

eZDOMNode::dump_mem (   $format,
  $charset = false 
)

Alias for libxml compatibility

eZDOMNode::elementAttributeValueByName (   $name,
  $attributeName 
)

Finds the first element named $name and returns the value of the attribute named $attributeName. If no element node is found or no attribute with the given name exists it returns false.

Note
This will only make sense for element nodes.
If multiple elements with that name is found false is returned.
See Also
elementByName, attributeValue
& eZDOMNode::elementByAttributeValue (   $attr,
  $value 
)
Parameters
attributename
attributevalue
Returns
element by attribute value
& eZDOMNode::elementByName (   $name)
Returns
The first element that is named $name. If multiple elements with that name is found false is returned.
Note
This will only make sense for element nodes.
See Also
elementsByName

Referenced by elementAttributeValueByName(), elementChildrenByName(), elementFirstChildByName(), and elementTextContentByName().

& eZDOMNode::elementChildrenByName (   $name)

Finds the first element named $name and returns the children of that node. If no element node is found it returns false.

Note
This will only make sense for element nodes.
If multiple elements with that name is found false is returned.
See Also
elementByName, children
& eZDOMNode::elementFirstChildByName (   $name)

Finds the first element named $name and returns the first child of that node. If no element node is found or there are not children it returns false.

Note
This will only make sense for element nodes.
If multiple elements with that name is found false is returned.
See Also
elementByName, firstChild
& eZDOMNode::elementsByName (   $name)
Returns
An array with elements that matches the name $name.
Note
This will only make sense for element nodes.
See Also
elementByName
& eZDOMNode::elementsTextContentByName (   $name)
Returns
An array with text contents taken from all child nodes which matches the name $name.
Note
This will only make sense for element nodes.
See Also
elementsByName, textContent
eZDOMNode::elementTextContentByName (   $name)

Finds the first element named $name and returns the text content of that node. If no element node is found or no text content exists it returns false.

Note
This will only make sense for element nodes.
If multiple elements with that name is found false is returned.
See Also
elementByName, textContent
eZDOMNode::eZDOMNode ( )

Initializes the DOM node.

Referenced by clone().

eZDOMNode::first_child ( )
Returns
first child of current dom node.
Note
added for compatibility with DOM XML library
& eZDOMNode::firstChild ( )
Returns
The first child of the node or false if there are no children.
Note
This will only make sense for element nodes.
W3C DOM function
eZDOMNode::get_attribute (   $attributeName)

Alias for libxml compatibility

eZDOMNode::get_elements_by_tagname (   $name)

Alias for libxml compatibility

eZDOMNode::getAttribute (   $attributeName)
eZDOMNode::getAttributeNS (   $namespaceURI,
  $localName 
)
eZDOMNode::hasAttributes ( )
Returns
true if the node has any attributes.
Note
This will only make sense for element nodes.
eZDOMNode::hasChildNodes ( )
eZDOMNode::hasChildren ( )
Returns
true if the node has children.
Note
This will only make sense for element nodes.
eZDOMNode::insertBefore ( $newNode,
$refNode 
)

Replaces child by the new one given.

Note
W3C DOM function
& eZDOMNode::lastChild ( )
Returns
The last child node or false if there are no children.
Note
This will only make sense for element nodes.
eZDOMNode::localName ( )

Returns the local name of the node if the node uses namespaces. If not false is returned.

eZDOMNode::name ( )
Returns
The name of the node.

For element and attributes nodes this will the name supplied when creating the node, for text nodes it returns #text and CDATA returns #cdata-section

Referenced by removeAttribute(), removeNamedAttribute(), and removeNamedChildren().

eZDOMNode::namespaceURI ( )
Returns
The namespace URI for the node or false if no URI

Referenced by toString().

& eZDOMNode::nextSibling ( )
Note
emulation of W3C DOM property
eZDOMNode::node_value ( )
Returns
node value of current dom node.
Note
added for compatibility with DOM XML library
eZDOMNode::prefix ( )
Returns
The prefix of the nodes name, this will be the namespace for the node.

Referenced by toString().

& eZDOMNode::previousSibling ( )
Note
emulation of W3C DOM property
eZDOMNode::remove_attribute (   $name)

Alias for libxml compatibility

eZDOMNode::removeAttribute (   $name)
eZDOMNode::removeAttributeNS (   $namespaceURI,
  $localName 
)
eZDOMNode::removeAttributes ( )

Removes all attribute from the node.

Note
This will only make sense for element nodes.
eZDOMNode::removeChild ( $childToRemove)

Removes child by the given child object.

Note
W3C DOM function
eZDOMNode::removeChildren ( )

Removes all child nodes from the current node.

Note
This will only make sense for element nodes.
eZDOMNode::removeLastChild ( )

Removes the last child node of the current node.

Note
This will only make sense for element nodes.
eZDOMNode::removeNamedAttribute (   $name)

Removes the attribute node named $name.

Returns
The removed attribute node or false if no such node exists.
Note
This will only make sense for element nodes.

Referenced by remove_attribute(), and set_attribute().

eZDOMNode::removeNamedChildren (   $name)

Removes all child nodes that matches the name $name.

Returns
true if it removed any nodes, otherwise false.
Note
This will only make sense for element nodes.
eZDOMNode::replaceChild ( $newChild,
$oldChild 
)

Replaces child by the new one given.

Note
W3C DOM function
eZDOMNode::set_attribute (   $name,
  $value 
)
eZDOMNode::setAttribute (   $name,
  $value 
)
eZDOMNode::setAttributeNS (   $namespaceURI,
  $qualifiedName,
  $value 
)
eZDOMNode::setContent (   $content)

Sets the content of the node to the $content.

Note
This will only make sense for text and CDATA nodes.
eZDOMNode::setName (   $name)

Sets the current name to $name.

eZDOMNode::setNamespaceURI (   $uri)

Sets the namespace URI of the node to $uri.

eZDOMNode::setPrefix (   $value)

Sets the namespace prefix for this node to $value.

eZDOMNode::setType (   $type)

Sets the node type to $type.

Use one of the following defines for the type:

  • EZ_XML_NODE_ELEMENT - Element nodes
  • EZ_XML_NODE_ATTRIBUTE - Attribute nodes
  • EZ_XML_NODE_TEXT - Text nodes
  • EZ_XML_NODE_CDATASECTION - CDATA nodes
eZDOMNode::textContent ( )
Returns
The content() of the first child node or false if there are no children.
Note
This will only make sense for element nodes.
See Also
elementTextContentByName
eZDOMNode::toString (   $level,
  $charset = false,
  $convertSpecialChars = true 
)
Returns
A string that represents the current node. The string will be created according to the node type which are:
  • Element node, places the name in <>, expands all attributes and calls toString() on all children.
  • Text node, returns the content() by escaping the characters & < > ' and ".
  • CDATA node, returns the text wrapped in <![CDATA[ and ]]
Parameters
$levelThe current tab level, starts at 0 and is increased by 1 for each recursion
$charsetWhich charset the text will be encoded in, currently not used

Example strings.

'<song name="Shine On You Crazy Diamond" track="1" />'
'This &amp; that &quot;wrapped&quot; in &lt;div&gt; tags'
'<![CDATA[This & that "wrapped" in <div> tags'
Note
This will only make sense for element nodes.

Referenced by dump_mem().

eZDOMNode::type ( )
Returns
An integer value which describes the type of node.

The type is one of:

  • 1 - Element node, that is a node which contains attributes and children.
  • 2 - Attribute node, this is a node which contains a name and a value.
  • 3 - Text node, this is a node which contains a text string
  • 4 - CDATA node, this is a node which contains a text string
eZDOMNode::writeDebug ( $node,
  $text,
  $showAttributes = false,
  $showParent = false 
)

Outputs DOM subtree to the debug output in the easy readable form.

Parameters
nodesubtree root node
eZDOMNode::writeDebugStr ( $node,
  $text 
)

Outputs XML from DOM as a string.

Parameters
nodesubtree root node

Member Data Documentation

eZDOMNode::$Attributes = array()
private

Attributes.

Referenced by attributes(), and clone().

eZDOMNode::$Children = array()
private

Subnodes.

Referenced by children(), and clone().

eZDOMNode::$content = ""
private

Content of the node.

Referenced by eZDOMNode(), and setContent().

eZDOMNode::$Content = ""
private

Referenced by clone(), content(), node_value(), and toString().

eZDOMNode::$flag = false
private
eZDOMNode::$LocalName = false
private

The local part of a name. E.g: book:title, title is the local part.

Referenced by clone(), and localName().

eZDOMNode::$Name = false
private

Name of the node.

Referenced by clone(), eZDOMNode(), and name().

eZDOMNode::$NamespaceURI = false
private

Contains the namespace URI. E.g. xmlns="http://ez.no/article/", http://ez.no/article/ would be the namespace URI.

Referenced by clone(), and namespaceURI().

eZDOMNode::$nodeName = null
private

DOM W3C compatibility.

eZDOMNode::$parentNode = false
private

Reference to the parent node.

Available only if Document has been created with parameter $setParentNode = true or parsed with eZXML::domTree function with $params["SetParentNode"] = true

Referenced by nextSibling(), and previousSibling().

eZDOMNode::$Prefix = false
private

contains the namespace prefix. E.g: book:title, book is the prefix

Referenced by clone(), and prefix().

eZDOMNode::$tagname = null
private

tagname, added for DOM XML compatibility.

Referenced by eZDOMNode().

eZDOMNode::$type
private

Type of the DOM node. ElementNode=1, AttributeNode=2, TextNode=3, CDATASectionNode=4.

Referenced by eZDOMNode(), and setType().

eZDOMNode::$Type = EZ_XML_NODE_ELEMENT
private

Referenced by clone(), and type().


The documentation for this class was generated from the following file: