eZDOMDocument Class Reference
[XML parser and DOM library]

eZDOMDocument handles DOM nodes in DOM documents More...

List of all members.

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
 $NamedNodes = array()
 Contains an array of reference to the named nodes.
 $NamedNodesNS = array()
 Contains an array of references to the named nodes with namespace.
 $Namespaces = array()
 Contains an array of the registered namespaces and their aliases.
 $Root
 Reference to the first child of the DOM document.
 $setParentNode = false
 If false eZDOMNode::parentNode will be not set.
 $Version
 XML version.

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>

Definition at line 108 of file ezdomdocument.php.


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()

Definition at line 167 of file ezdomdocument.php.

Referenced by setRoot().

eZDOMDocument::cleanup (  ) 

Definition at line 122 of file ezdomdocument.php.

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

Alias for libXML compatibility

Definition at line 421 of file ezdomdocument.php.

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

Creates recursive array from DOMNodeElement

Definition at line 346 of file ezdomdocument.php.

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

eZDOMDocument::createAttribute ( name  ) 

Definition at line 799 of file ezdomdocument.php.

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:
$prefix Namespace prefix which will be placed before the attribute name
$uri The 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"

Definition at line 577 of file ezdomdocument.php.

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:
$uri The unique URI for the namespace
$name The name of the attribute
$content The content of the attribute
      $dom->createAttributeNodeNS( 'http://music.org/groups',
                                   'name',
                                   'Pink Floyd' );

The resulting XML text will be

      name="Pink Floyd"

Definition at line 609 of file ezdomdocument.php.

eZDOMDocument::createAttributeNS ( namespaceURI,
qualifiedName 
)

Definition at line 785 of file ezdomdocument.php.

Referenced by eZDOMNode::setAttributeNS().

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:
$text The text string which will be stored in the node
      $dom->createCDATANode( 'http://ez.no' );

The resulting XML text will be

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

Definition at line 292 of file ezdomdocument.php.

Referenced by createElementCDATANode().

& eZDOMDocument::createElement ( name  ) 

Definition at line 758 of file ezdomdocument.php.

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:
$name The name of the element node.
$text The text string which will be stored in the CDATA node
$attributes An 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

Definition at line 485 of file ezdomdocument.php.

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:
$name The name of the element node.
$attributes An 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' />

Definition at line 405 of file ezdomdocument.php.

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(), eZTimeType::serializeContentClassAttribute(), eZStringType::serializeContentClassAttribute(), eZPriceType::serializeContentClassAttribute(), eZObjectRelationType::serializeContentClassAttribute(), eZObjectRelationListType::serializeContentClassAttribute(), eZMultiPriceType::serializeContentClassAttribute(), eZMatrixType::serializeContentClassAttribute(), eZEnumType::serializeContentClassAttribute(), eZDateType::serializeContentClassAttribute(), eZDateTimeType::serializeContentClassAttribute(), eZBooleanType::serializeContentClassAttribute(), eZUserType::serializeContentObjectAttribute(), eZURLType::serializeContentObjectAttribute(), eZMediaType::serializeContentObjectAttribute(), and eZBinaryFileType::serializeContentObjectAttribute().

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

Creates DOMNodeElement recursivly from recursive array

Definition at line 308 of file ezdomdocument.php.

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:
$uri The namespace URI for the element
$name The 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

Definition at line 515 of file ezdomdocument.php.

eZDOMDocument::createElementNS ( namespaceURI,
qualifiedName 
)

Definition at line 771 of file ezdomdocument.php.

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:
$name The name of the element node.
$text The text string which will be stored in the text node
$attributes An 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

Definition at line 451 of file ezdomdocument.php.

Referenced by eZContentClassPackageHandler::classDOMTree(), eZContentObjectPackageHandler::createDOMNodeFromFile(), eZContentObjectPackageHandler::createSiteAccessListNode(), eZContentObjectPackageHandler::createTopNodeListDOMNode(), eZContentObjectVersion::serialize(), eZXMLTextType::serializeContentClassAttribute(), eZTextType::serializeContentClassAttribute(), eZStringType::serializeContentClassAttribute(), eZSelectionType::serializeContentClassAttribute(), eZRangeOptionType::serializeContentClassAttribute(), eZPackageType::serializeContentClassAttribute(), eZOptionType::serializeContentClassAttribute(), eZObjectRelationListType::serializeContentClassAttribute(), eZMultiOptionType::serializeContentClassAttribute(), eZMediaType::serializeContentClassAttribute(), eZMatrixType::serializeContentClassAttribute(), eZIntegerType::serializeContentClassAttribute(), eZIniSettingType::serializeContentClassAttribute(), eZImageType::serializeContentClassAttribute(), eZIdentifierType::serializeContentClassAttribute(), eZFloatType::serializeContentClassAttribute(), eZBinaryFileType::serializeContentClassAttribute(), eZURLType::serializeContentObjectAttribute(), eZTimeType::serializeContentObjectAttribute(), eZSubtreeSubscriptionType::serializeContentObjectAttribute(), serializeContentObjectAttribute(), eZObjectRelationType::serializeContentObjectAttribute(), eZKeywordType::serializeContentObjectAttribute(), eZIniSettingType::serializeContentObjectAttribute(), eZDateType::serializeContentObjectAttribute(), eZDateTimeType::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:
$text The text string which will be stored in the node
      $dom->createTextNode( 'Edge' );

The resulting XML text will be

      Edge

Definition at line 257 of file ezdomdocument.php.

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

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

Alias for libxml compatibility

Definition at line 719 of file ezdomdocument.php.

& eZDOMDocument::elementsByName ( name  ) 

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

Returns:
An array with eZDOMNode elements.

Definition at line 197 of file ezdomdocument.php.

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.

Definition at line 219 of file ezdomdocument.php.

eZDOMDocument::eZDOMDocument ( name = "",
setParentNode = false 
)

Initializes the DOM document object with the name $name.

Definition at line 113 of file ezdomdocument.php.

eZDOMDocument::get_elements_by_tagname ( name  ) 

Alias for libxml compatibility

Definition at line 210 of file ezdomdocument.php.

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

Definition at line 148 of file ezdomdocument.php.

eZDOMDocument::namespaceByAlias ( alias  ) 

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

Returns:
An array with eZDOMNode elements.

Definition at line 228 of file ezdomdocument.php.

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.

Definition at line 732 of file ezdomdocument.php.

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().

Definition at line 747 of file ezdomdocument.php.

& eZDOMDocument::root (  ) 
Returns:
The document root node if it exists, if not false is returned.

Definition at line 139 of file ezdomdocument.php.

eZDOMDocument::setDocTypeDefinition ( url = false,
alias = false,
explict = false 
)

Adds the URL to a DTD to the document.

Parameters:
$url A vaild URL
$alias An alias representing the document, for example
-//My Company//DTD XMLEXPORT V 1.0//EN 
$explict Declare if DTD must be used.

Definition at line 642 of file ezdomdocument.php.

eZDOMDocument::setName ( name  ) 

Sets the document name to $name.

Definition at line 131 of file ezdomdocument.php.

eZDOMDocument::setRoot ( &$  node  ) 

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

Definition at line 157 of file ezdomdocument.php.

eZDOMDocument::setStylesheet ( url  ) 

Adds the URL to a XSLT stylesheet to the document.

Parameters:
$url A vaild URL or array of URLs

Definition at line 626 of file ezdomdocument.php.

eZDOMDocument::toString ( charset = true,
charsetConversion = true,
convertSpecialChars = true 
)

Returns a XML string representation of the DOM document.

Parameters:
$charset The name of the output charset or false to use UTF-8 (default in XML)
$charsetConversion Controls 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

Definition at line 668 of file ezdomdocument.php.

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)

Definition at line 182 of file ezdomdocument.php.

Referenced by appendChild().


Member Data Documentation

eZDOMDocument::$Name [private]

Document name

Definition at line 810 of file ezdomdocument.php.

eZDOMDocument::$NamedNodes = array() [private]

Contains an array of reference to the named nodes.

Definition at line 816 of file ezdomdocument.php.

eZDOMDocument::$NamedNodesNS = array() [private]

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

Definition at line 819 of file ezdomdocument.php.

eZDOMDocument::$Namespaces = array() [private]

Contains an array of the registered namespaces and their aliases.

Definition at line 822 of file ezdomdocument.php.

eZDOMDocument::$Root [private]

Reference to the first child of the DOM document.

Definition at line 825 of file ezdomdocument.php.

eZDOMDocument::$setParentNode = false [private]

If false eZDOMNode::parentNode will be not set.

Definition at line 829 of file ezdomdocument.php.

Referenced by eZDOMDocument().

eZDOMDocument::$Version [private]

XML version.

Definition at line 813 of file ezdomdocument.php.


The documentation for this class was generated from the following file:
Generated on Mon Jul 12 07:10:25 2010 for eZ publish by  doxygen 1.6.3