eZPublish  3.8
eZDOMDocument Class Reference

eZDOMDocument handles DOM nodes in DOM documents More...

Public Member Functions

 appendChild (&$node)
 
 cleanup ()
 
 create_element ($name, $attributes=array())
 
 createAttribute ($name)
 
 createAttributeNS ($namespaceURI, $qualifiedName)
 
createElement ($name)
 
 createElementNS ($namespaceURI, $qualifiedName)
 
 dump_mem ($charset=true, $conversion=true)
 
elementsByName ($name)
 
elementsByNameNS ($name, $namespaceURI)
 
 eZDOMDocument ($name="", $setParentNode=false)
 
 get_elements_by_tagname ($name)
 
get_root ()
 
 namespaceByAlias ($alias)
 
 registerElement (&$node)
 
 registerNamespaceAlias ($alias, $namespace)
 
root ()
 
 setDocTypeDefinition ($url=false, $alias=false, $explict=false)
 
 setName ($name)
 
 setRoot (&$node)
 
 setStylesheet ($url)
 
 toString ($charset=true, $charsetConversion=true, $convertSpecialChars=true)
 
 updateParentNodeProperty (&$node)
 

Static Public Member Functions

 createArrayFromDOMNode ($domNode)
 
 createAttributeNamespaceDefNode ($prefix, $uri)
 
 createAttributeNode ($name, $content, $prefix=false)
 
 createAttributeNodeNS ($uri, $name, $content)
 
 createCDATANode ($text)
 
 createElementCDATANode ($name, $text, $attributes=array())
 
 createElementNode ($name, $attributes=array())
 
 createElementNodeFromArray ($name, $array)
 
 createElementNodeNS ($uri, $name)
 
 createElementTextNode ($name, $text, $attributes=array())
 
 createTextNode ($text)
 

Private Attributes

 $Name
 Document name. More...
 
 $NamedNodes = array()
 Contains an array of reference to the named nodes. More...
 
 $NamedNodesNS = array()
 Contains an array of references to the named nodes with namespace. More...
 
 $Namespaces = array()
 Contains an array of the registered namespaces and their aliases. More...
 
 $Root
 Reference to the first child of the DOM document. More...
 
 $setParentNode = false
 If false eZDOMNode::parentNode will be not set. More...
 
 $Version
 XML version. More...
 

Detailed Description

eZDOMDocument handles DOM nodes in DOM documents

The DOM document keeps a tree of DOM nodes and maintains information on the various namespaces in the tree. It also has helper functions for creating nodes and serializing the tree into text.

Accessing and changing the name of the document is done using name() and setName().

Accessing the tree is done using the root() method, use setRoot() to set a new root node. The method appendChild() will do the same as setRoot().

For fetching nodes globally the methods elementsByName(), elementsByNameNS() and namespaceByAlias() can be used. They will fetch nodes according to the fetch criteria no matter where they are in the tree.

Creating new nodes is most easily done with the helper methods createTextNode(), createCDATANode(), createElementNode() and createAttributeNode(). They take care of creating the node with the correct type and does proper initialization.

Creating typical structures is also possible with the helper methods createElementTextNode(), createElementCDATANode(), createElementNodeNS(), createAttributeNamespaceDefNode() and createAttributeNodeNS(). This will not only create the node itself but also the correct subchild, attribute or namespace.

After nodes are created they can be registered with the methods registerElement(), registerNamespaceAlias(). This ensures that they are available globally in the DOM document.

Serializing the tree structure is done using toString(), this also allows specifying the character set of the output.

Example of using the DOM document to create a node structure.

$doc = new eZDOMDocument();
$doc->setName( "FishCatalogue" );
$root = $doc->createElementNode( "FishCatalogue" );
$doc->setRoot( $root );
$freshWater = $doc->createElementNode( "FreshWater" );
$root->appendChild( $freshWater );
$saltWater = $doc->createElementNode( "SaltWater" );
$root->appendChild( $saltWater );
$guppy = $doc->createElementNode( "Guppy" );
$guppy->appendChild( $doc->createTextNode( "Guppy is a small livebreeder." ) );
$freshWater->appendChild( $guppy );
$cod = $doc->createElementNode( "Cod" );
$saltWater->appendChild( $cod );
$cod->appendChild( $doc->createCDATANode( "A big dull fish <-> !!" ) );
print( $doc->toString() );
// will print the following
<?xml version="1.0"?>
<FishCatalogue>
<FreshWater>
<Guppy>
Guppy is a small livebreeder. </Guppy>
</FreshWater>
<SaltWater>
<Cod>
<![CDATA[A big dull fish <-> !!]]> </Cod>
</SaltWater>
</FishCatalogue>

Member Function Documentation

eZDOMDocument::appendChild ( $node)

Sets the document root node to $node. If the parameter is not an eZDOMNode it will not be set.

See Also
setRoot()

Referenced by setRoot().

eZDOMDocument::cleanup ( )
eZDOMDocument::create_element (   $name,
  $attributes = array() 
)

Alias for libXML compatibility

eZDOMDocument::createArrayFromDOMNode (   $domNode)
static
Deprecated:
not compatible with W3C DOM standard

Creates recursive array from DOMNodeElement

Referenced by eZContentObjectPackageHandler\installFetchAliases(), and eZContentObjectPackageHandler\installOverrides().

eZDOMDocument::createAttribute (   $name)

Referenced by eZDOMNode\setAttribute().

eZDOMDocument::createAttributeNamespaceDefNode (   $prefix,
  $uri 
)
static
Deprecated:
Not compatible with W3C DOM standard. Use createAttributeNS instead.

Creates a DOM node of type attribute which is used for namespace definitions and returns it.

Parameters
$prefixNamespace prefix which will be placed before the attribute name
$uriThe unique URI for the namespace
$dom->createAttributeNamespaceDefNode( 'music-group',
'http://music.org/groups' );

The resulting XML text will be

xmlns:music-group="http://music.org/groups"

Referenced by eZContentObject\serialize().

eZDOMDocument::createAttributeNode (   $name,
  $content,
  $prefix = false 
)
static
eZDOMDocument::createAttributeNodeNS (   $uri,
  $name,
  $content 
)
static
Deprecated:
Not compatible with W3C DOM standard. Use createAttributeNS instead.

Creates a DOM node of type attribute which is used for namespace definitions and returns it.

Parameters
$uriThe unique URI for the namespace
$nameThe name of the attribute
$contentThe content of the attribute
$dom->createAttributeNodeNS( 'http://music.org/groups',
'name',
'Pink Floyd' );

The resulting XML text will be

name="Pink Floyd"
eZDOMDocument::createAttributeNS (   $namespaceURI,
  $qualifiedName 
)
eZDOMDocument::createCDATANode (   $text)
static

Creates a DOM node of type CDATA and returns it.

CDATA nodes are used to store text strings, use content() on the node to extract the text.

Parameters
$textThe text string which will be stored in the node
$dom->createCDATANode( 'http://ez.no' );

The resulting XML text will be

<![CDATA[http://ez.no]]>

Referenced by createElementCDATANode().

& eZDOMDocument::createElement (   $name)
eZDOMDocument::createElementCDATANode (   $name,
  $text,
  $attributes = array() 
)
static
Deprecated:
not compatible with W3C DOM standard

Creates a DOM node of type element and returns it. It will also create a DOM node of type CDATA and add it as child of the element node.

Parameters
$nameThe name of the element node.
$textThe text string which will be stored in the CDATA node
$attributesAn associative array with attribute names and attribute data. This can be used to quickly fill in element node attributes.
$dom->createElementCDATANode( 'name',
'Peter Molyneux',
array( 'type' => 'developer',
'game' => 'dungeon keeper' ) );

The resulting XML text will be

<name type='developer' game='dungeon keeper'><![CDATA[Peter Molyneux]]></name>
See Also
createCDATANode, createElementNode
eZDOMDocument::createElementNode (   $name,
  $attributes = array() 
)
static
Deprecated:
Use createElement and setAttribute instead.

Creates a DOM node of type element and returns it.

Element nodes are the basic node type in DOM tree, they are used to structure nodes. They can contain child nodes and attribute nodes accessible with children() and attributes().

Parameters
$nameThe name of the element node.
$attributesAn associative array with attribute names and attribute data. This can be used to quickly fill in node attributes.
$dom->createElementNode( 'song',
array( 'name' => 'Shine On You Crazy Diamond',
'track' => 1 ) );

The resulting XML text will be

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

Referenced by eZContentClassPackageHandler\classDOMTree(), create_element(), eZContentObjectPackageHandler\createDOMNodeFromFile(), createElementCDATANode(), createElementTextNode(), eZImageAliasHandler\createImageInformationNode(), eZContentObjectPackageHandler\createObjectListNode(), eZContentObjectPackageHandler\createSiteAccessListNode(), eZContentObjectPackageHandler\createTopNodeListDOMNode(), eZSOAPCodec\encodeValue(), eZContentObjectPackageHandler\generateFetchAliasArray(), eZContentObjectPackageHandler\generateOverrideSettingsArray(), eZContentObjectPackageHandler\generatePackage(), eZContentObjectPackageHandler\generateTemplateFilenameArray(), eZINIAddonPackageHandler\iniDOMTree(), eZPriceType\serializeContentClassAttribute(), eZBooleanType\serializeContentClassAttribute(), eZMultiPriceType\serializeContentClassAttribute(), eZDateType\serializeContentClassAttribute(), eZTimeType\serializeContentClassAttribute(), eZStringType\serializeContentClassAttribute(), eZSimplePrice\serializeContentClassAttribute(), eZMatrixType\serializeContentClassAttribute(), eZDateTimeType\serializeContentClassAttribute(), eZEnumType\serializeContentClassAttribute(), eZObjectRelationType\serializeContentClassAttribute(), eZObjectRelationListType\serializeContentClassAttribute(), eZURLType\serializeContentObjectAttribute(), eZUserType\serializeContentObjectAttribute(), eZBinaryFileType\serializeContentObjectAttribute(), and eZMediaType\serializeContentObjectAttribute().

eZDOMDocument::createElementNodeFromArray (   $name,
  $array 
)
static
Deprecated:
not compatible with W3C DOM standard

Creates DOMNodeElement recursivly from recursive array

Referenced by eZContentObjectPackageHandler\generateFetchAliasArray(), and eZContentObjectPackageHandler\generateOverrideSettingsArray().

eZDOMDocument::createElementNodeNS (   $uri,
  $name 
)
static
Deprecated:
Not compatible with W3C DOM standard. Use createElementNS instead.

Creates a DOM node of type element with a namespace and returns it.

Parameters
$uriThe namespace URI for the element
$nameThe name of the element node.
$dom->createElementNodeNS( 'http://ez.no/package',
'package' );

The resulting XML text will be

<package xmlns="http://ez.no/package" />
See Also
createElementNode
eZDOMDocument::createElementNS (   $namespaceURI,
  $qualifiedName 
)
eZDOMDocument::createElementTextNode (   $name,
  $text,
  $attributes = array() 
)
static
Deprecated:
Not compatible with W3C DOM standard

Creates a DOM node of type element and returns it. It will also create a DOM node of type text and add it as child of the element node.

Parameters
$nameThe name of the element node.
$textThe text string which will be stored in the text node
$attributesAn associative array with attribute names and attribute data. This can be used to quickly fill in element node attributes.
$dom->createElementTextNode( 'name',
'Archer Maclean',
array( 'id' => 'archer',
'game' => 'ik+' ) );

The resulting XML text will be

<name id='archer' game='ik+'>Archer Maclean</name>
See Also
createTextNode, createElementNode

Referenced by eZContentClassPackageHandler\classDOMTree(), eZContentObjectPackageHandler\createDOMNodeFromFile(), eZContentObjectPackageHandler\createSiteAccessListNode(), eZContentObjectPackageHandler\createTopNodeListDOMNode(), eZContentObjectVersion\serialize(), eZRangeOptionType\serializeContentClassAttribute(), eZPackageType\serializeContentClassAttribute(), eZTextType\serializeContentClassAttribute(), eZFloatType\serializeContentClassAttribute(), eZOptionType\serializeContentClassAttribute(), eZStringType\serializeContentClassAttribute(), eZSelectionType\serializeContentClassAttribute(), eZMultiOptionType\serializeContentClassAttribute(), eZIdentifierType\serializeContentClassAttribute(), eZMatrixType\serializeContentClassAttribute(), eZXMLTextType\serializeContentClassAttribute(), eZIntegerType\serializeContentClassAttribute(), eZIniSettingType\serializeContentClassAttribute(), eZImageType\serializeContentClassAttribute(), eZBinaryFileType\serializeContentClassAttribute(), eZMediaType\serializeContentClassAttribute(), eZObjectRelationListType\serializeContentClassAttribute(), eZSubtreeSubscriptionType\serializeContentObjectAttribute(), eZURLType\serializeContentObjectAttribute(), eZKeywordType\serializeContentObjectAttribute(), eZDateType\serializeContentObjectAttribute(), eZTimeType\serializeContentObjectAttribute(), serializeContentObjectAttribute(), eZDateTimeType\serializeContentObjectAttribute(), eZObjectRelationType\serializeContentObjectAttribute(), eZIniSettingType\serializeContentObjectAttribute(), and eZDataType\serializeContentObjectAttribute().

eZDOMDocument::createTextNode (   $text)
static

Creates a DOM node of type text and returns it.

Text nodes are used to store text strings, use content() on the node to extract the text.

Parameters
$textThe text string which will be stored in the node
$dom->createTextNode( 'Edge' );

The resulting XML text will be

Edge

Referenced by createElementTextNode(), eZImageAliasHandler\createImageInformationNode(), eZSOAPCodec\encodeValue(), eZSOAPResponse\payload(), and eZURLType\serializeContentObjectAttribute().

eZDOMDocument::dump_mem (   $charset = true,
  $conversion = true 
)

Alias for libxml compatibility

& eZDOMDocument::elementsByName (   $name)

Finds all element nodes which matches the name $name and returns it.

Returns
An array with eZDOMNode elements.

Referenced by get_elements_by_tagname().

& eZDOMDocument::elementsByNameNS (   $name,
  $namespaceURI 
)

Finds all element nodes which matches the name $name and namespace URI $namespaceURI and returns it.

Returns
An array with eZDOMNode elements.
eZDOMDocument::eZDOMDocument (   $name = "",
  $setParentNode = false 
)

Initializes the DOM document object with the name $name.

eZDOMDocument::get_elements_by_tagname (   $name)

Alias for libxml compatibility

& eZDOMDocument::get_root ( )
Returns
The document root node if it exists, if not false is returned. Extra method for libxml compatibility.
eZDOMDocument::namespaceByAlias (   $alias)

Finds all element nodes which matches the namespace alias $alias and returns it.

Returns
An array with eZDOMNode elements.
eZDOMDocument::registerElement ( $node)

Registers the node element $node in the DOM document. This involves extracting the name of the node and add it to the name lookup table which elementsByName() uses, then adding it to the namespace lookup table which elementsByNameNS() uses.

Note
This will not insert the node into the node tree.

Referenced by createElement().

eZDOMDocument::registerNamespaceAlias (   $alias,
  $namespace 
)

Register the namespace alias $alias to point to the namespace $namespace.

The namespace can then later on be fetched with namespaceByAlias().

& eZDOMDocument::root ( )
Returns
The document root node if it exists, if not false is returned.
eZDOMDocument::setDocTypeDefinition (   $url = false,
  $alias = false,
  $explict = false 
)

Adds the URL to a DTD to the document.

Parameters
$urlA vaild URL
$aliasAn alias representing the document, for example
-//My Company//DTD XMLEXPORT V 1.0//EN
$explictDeclare if DTD must be used.
eZDOMDocument::setName (   $name)

Sets the document name to $name.

eZDOMDocument::setRoot ( $node)

Sets the document root node to $node. If the parameter is not an eZDOMNode it will not be set.

eZDOMDocument::setStylesheet (   $url)

Adds the URL to a XSLT stylesheet to the document.

Parameters
$urlA vaild URL or array of URLs
eZDOMDocument::toString (   $charset = true,
  $charsetConversion = true,
  $convertSpecialChars = true 
)

Returns a XML string representation of the DOM document.

Parameters
$charsetThe name of the output charset or false to use UTF-8 (default in XML)
$charsetConversionControls whether the resulting text is converted to the specified charset or not.

The $charsetConversion parameter can be useful when you know the inserted texts are in the correct charset, turning conversion off can speed things up.

The XML creation is done by calling the eZDOMNode::toString() function on the root node and let that handle the rest.

Note
The charset conversion is smart enough to only do conversion when required
Using charset conversion will require the ezi18n library being installed

Referenced by dump_mem().

eZDOMDocument::updateParentNodeProperty ( $node)

Updates parentNode of the tree according to setParentNode property of the document. (set false, if setParentNode is false)

Referenced by appendChild().

Member Data Documentation

eZDOMDocument::$Name
private

Document name.

eZDOMDocument::$NamedNodes = array()
private

Contains an array of reference to the named nodes.

eZDOMDocument::$NamedNodesNS = array()
private

Contains an array of references to the named nodes with namespace.

eZDOMDocument::$Namespaces = array()
private

Contains an array of the registered namespaces and their aliases.

eZDOMDocument::$Root
private

Reference to the first child of the DOM document.

Referenced by get_root(), and root().

eZDOMDocument::$setParentNode = false
private

If false eZDOMNode::parentNode will be not set.

Referenced by eZDOMDocument().

eZDOMDocument::$Version
private

XML version.


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