## Apache Zeta Components Manual :: Docs For Class ezcTreeXml

### Tree::ezcTreeXml

### Class ezcTreeXml

ezcTreeXml is an implementation of a tree backend that operates on an XML file.

Example:

1. <?php
2. // Create a new tree in a new XML file
3. $tree=ezcTreeXml :: create (
4. 'new-tree.xml',
5. new ezcTreeXmlInternalDataStore ()
6. );
8. // Open an existing XML file containing a tree structure
9. $tree=new ezcTreeXml (
10. 'existing-tree.xml',
11. new ezcTreeXmlInternalDataStore ()
12. );
13. ?>

See ezcTree for examples on how to operate on the tree.

Source for this file: /Tree/src/backends/xml.php

    ezcTree
       |
       --ezcTreeXml

Version: | //autogentag//

### Constants

`relaxNG = '<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns:etd="http://components.ez.no/Tree/data" ns="http://components.ez.no/Tree" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<start>
<element name="tree">
<optional>
<attribute name="prefix">
<data type="ID"/>
</attribute>
</optional>
<optional>
<attribute name="lastNodeId">
<data type="string"/>
</attribute>
</optional>
<optional>
<ref name="node"/>
</optional>
</element>
</start>
<define name="node">
<element name="node">
<attribute name="id">
<data type="ID"/>
</attribute>
<optional>
<element name="etd:data">
<text/>
</element>
</optional>
<zeroOrMore>
<ref name="node"/>
</zeroOrMore>
</element>
</define>
</grammar>'`

Contains the relax-NG schema to validate the tree XML.

### Properties

string | read/write | `$nodeClassName` Which class is used as tree node - this class *must* inherit the ezcTreeNode class.
string | read | `$prefix` The prefix that is used to prefix node IDs with in the tree.
ezcTreeXmlDataStore | read | `$store` The data store that is used for retrieving/storing data.

### Inherited Member Variables

From ezcTree
protected | `ezcTree::$inTransaction`
protected | `ezcTree::$inTransactionCommit`
protected | `ezcTree::$properties`

### Method Summary

public static ezcTreeXml | `create( $xmlFile , $store , [ $prefix = 'id'] )` Creates a new XML tree in the file $xmlFile using $store as data store.
public ezcTreeXml | `__construct( $xmlFile , $store )` Constructs a new ezcTreeXml object from the XML data in $xmlFile and using the $store to retrieve data from.
public void | `addChild( $parentId , $childNode )` Adds the node $childNode as child of the node with ID $parentId.
public void | `delete( $nodeId )` Deletes the node with ID $nodeId from the tree, including all its children.
public ezcTreeNodeList | `fetchChildren( $nodeId )` Returns all the children of the node with ID $nodeId.
public ezcTreeNode | `fetchParent( $nodeId )` Returns the parent node of the node with ID $nodeId.
public ezcTreeNodeList | `fetchPath( $nodeId )` Returns all the nodes in the path from the root node to the node with ID $nodeId, including those two nodes.
public ezcTreeNodeList | `fetchSubtree( $nodeId )` Alias for fetchSubtreeDepthFirst().
public ezcTreeNodeList | `fetchSubtreeBreadthFirst( $nodeId )` Returns the node with ID $nodeId and all its children, sorted according to the Breadth-first sorting algorithm.
public ezcTreeNodeList | `fetchSubtreeDepthFirst( $nodeId )` Returns the node with ID $nodeId and all its children, sorted according to the Depth-first sorting algorithm.
public void | `fixateTransaction( )` Fixates the transaction (saves the XML file).
protected integer | `generateNodeID( )` This method generates the next node ID.
public int | `getChildCount( $nodeId )` Returns the number of direct children of the node with ID $nodeId.
public int | `getChildCountRecursive( $nodeId )` Returns the number of children of the node with ID $nodeId, recursively.
public int | `getPathLength( $nodeId )` Returns the distance from the root node to the node with ID $nodeId.
public ezcTreeNode | `getRootNode( )` Returns the root node.
public bool | `hasChildNodes( $nodeId )` Returns whether the node with ID $nodeId has children.
public bool | `isChildOf( $childId , $parentId )` Returns whether the node with ID $childId is a direct child of the node with ID $parentId.
public bool | `isDescendantOf( $childId , $parentId )` Returns whether the node with ID $childId is a direct or indirect child of the node with ID $parentId.
public bool | `isSiblingOf( $child1Id , $child2Id )` Returns whether the nodes with IDs $child1Id and $child2Id are siblings (ie, they share the same parent).
public void | `move( $nodeId , $targetParentId )` Moves the node with ID $nodeId as child to the node with ID $targetParentId.
public bool | `nodeExists( $nodeId )` Returns whether the node with ID $nodeId exists.
public void | `saveFile( )` Saves the internal DOM representation of the tree back to disk.
public void | `setRootNode( $node )` Sets a new node as root node, this also wipes out the whole tree.

### Inherited Methods

From ezcTree
public void | `ezcTree::accept()` Implements the accept method for visiting.
public abstract void | `ezcTree::addChild()` Adds the node $childNode as child of the node with ID $parentId.
protected void | `ezcTree::addTransactionItem()` Adds a new transaction item to the list.
public void | `ezcTree::beginTransaction()` Starts an transaction in which all tree modifications are queued until the transaction is committed with the commit() method.
protected void | `ezcTree::checkNodeId()` This method checks whether a node ID is valid to be used in a backend.
public void | `ezcTree::commit()` Commits the transaction by running the stored instructions to modify the tree structure.
public static void | `ezcTree::copy()` Copies the tree in $from to the empty tree in $to.
public ezcTreeNode | `ezcTree::createNode()` Creates a new tree node with node ID $nodeId and $data.
public abstract void | `ezcTree::delete()` Deletes the node with ID $nodeId from the tree, including all its children.
public abstract ezcTreeNodeList | `ezcTree::fetchChildren()` Returns all the children of the node with ID $nodeId.
public ezcTreeNode | `ezcTree::fetchNodeById()` Returns the node identified by the ID $nodeId.
public abstract ezcTreeNode | `ezcTree::fetchParent()` Returns the parent node of the node with ID $nodeId.
public abstract ezcTreeNodeList | `ezcTree::fetchPath()` Returns all the nodes in the path from the root node to the node with ID $nodeId, including those two nodes.
public abstract ezcTreeNodeList | `ezcTree::fetchSubtree()` Alias for fetchSubtreeDepthFirst().
public abstract ezcTreeNodeList | `ezcTree::fetchSubtreeBreadthFirst()` Returns the node with ID $nodeId and all its children, sorted according to the Breadth-first sorting algorithm.
public abstract ezcTreeNodeList | `ezcTree::fetchSubtreeDepthFirst()` Returns the node with ID $nodeId and all its children, sorted according to the Depth-first sorting algorithm.
protected abstract integer | `ezcTree::generateNodeID()` This method generates the next node ID.
public abstract int | `ezcTree::getChildCount()` Returns the number of direct children of the node with ID $nodeId.
public abstract int | `ezcTree::getChildCountRecursive()` Returns the number of children of the node with ID $nodeId, recursively.
public abstract int | `ezcTree::getPathLength()` Returns the distance from the root node to the node with ID $nodeId.
public abstract ezcTreeNode | `ezcTree::getRootNode()` Returns the root node.
public abstract bool | `ezcTree::hasChildNodes()` Returns whether the node with ID $nodeId has children.
public bool | `ezcTree::inTransaction()` Returns whether we are currently in a transaction or not
public bool | `ezcTree::inTransactionCommit()` Returns whether we are currently in a transaction commit state or not
public abstract bool | `ezcTree::isChildOf()` Returns whether the node with ID $childId is a direct child of the node with ID $parentId.
public abstract bool | `ezcTree::isDescendantOf()` Returns whether the node with ID $childId is a direct or indirect child of the node with ID $parentId.
public abstract bool | `ezcTree::isSiblingOf()` Returns whether the nodes with IDs $child1Id and $child2Id are siblings (ie, they share the same parent).
public abstract void | `ezcTree::move()` Moves the node with ID $nodeId as child to the node with ID $targetParentId.
public abstract bool | `ezcTree::nodeExists()` Returns whether the node with ID $nodeId exists.
public void | `ezcTree::rollback()` Rolls back the transaction by clearing all stored instructions.
public abstract void | `ezcTree::setRootNode()` Sets a new node as root node, this also wipes out the whole tree.

### Methods

#### create

static ezcTreeXml create( string $xmlFile , ezcTreeXmlDataStore $store , [string $prefix = 'id'] )

Creates a new XML tree in the file $xmlFile using $store as data store.

The $prefix option can be used to change the prefix that is used for IDs in the created tree. By default this is set to "id" so that numerical node IDs are not a problem.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$xmlFile` | string |
`$store` | ezcTreeXmlDataStore |
`$prefix` | string |

#### __construct

ezcTreeXml __construct( string $xmlFile , ezcTreeXmlDataStore $store )

Constructs a new ezcTreeXml object from the XML data in $xmlFile and using the $store to retrieve data from.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$xmlFile` | string |
`$store` | ezcTreeXmlDataStore |

#### addChild

void addChild( string $parentId , ezcTreeNode $childNode )

Adds the node $childNode as child of the node with ID $parentId.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$parentId` | string |
`$childNode` | ezcTreeNode |

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::addChild()` | Adds the node $childNode as child of the node with ID $parentId.

#### delete

void delete( string $nodeId )

Deletes the node with ID $nodeId from the tree, including all its children.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$nodeId` | string |

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::delete()` | Deletes the node with ID $nodeId from the tree, including all its children.

#### fetchChildren

ezcTreeNodeList fetchChildren( string $nodeId )

Returns all the children of the node with ID $nodeId.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$nodeId` | string |

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::fetchChildren()` | Returns all the children of the node with ID $nodeId.

#### fetchParent

ezcTreeNode fetchParent( string $nodeId )

Returns the parent node of the node with ID $nodeId.

This method returns null if there is no parent node.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$nodeId` | string |

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::fetchParent()` | Returns the parent node of the node with ID $nodeId.

#### fetchPath

ezcTreeNodeList fetchPath( string $nodeId )

Returns all the nodes in the path from the root node to the node with ID $nodeId, including those two nodes.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$nodeId` | string |

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::fetchPath()` | Returns all the nodes in the path from the root node to the node with ID $nodeId, including those two nodes.

#### fetchSubtree

ezcTreeNodeList fetchSubtree( string $nodeId )

Alias for fetchSubtreeDepthFirst().

##### Parameters:

Name | Type | Description
--- | --- | ---
`$nodeId` | string |

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::fetchSubtree()` | Alias for fetchSubtreeDepthFirst().

#### fetchSubtreeBreadthFirst

ezcTreeNodeList fetchSubtreeBreadthFirst( string $nodeId )

Returns the node with ID $nodeId and all its children, sorted according to the Breadth-first sorting algorithm.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$nodeId` | string |

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::fetchSubtreeBreadthFirst()` | Returns the node with ID $nodeId and all its children, sorted according to the Breadth-first sorting algorithm.

#### fetchSubtreeDepthFirst

ezcTreeNodeList fetchSubtreeDepthFirst( string $nodeId )

Returns the node with ID $nodeId and all its children, sorted according to the Depth-first sorting algorithm.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$nodeId` | string |

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::fetchSubtreeDepthFirst()` | Returns the node with ID $nodeId and all its children, sorted according to the Depth-first sorting algorithm.

#### fixateTransaction

void fixateTransaction( )

Fixates the transaction (saves the XML file).

#### generateNodeID

integer generateNodeID( )

This method generates the next node ID.

It uses the stored last generated ID, and also stores this in an attribute on the root node so that it can be correctly incremented without having to search for the last generated ID in the whole tree.

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::generateNodeID()` | This method generates the next node ID.

#### getChildCount

int getChildCount( string $nodeId )

Returns the number of direct children of the node with ID $nodeId.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$nodeId` | string |

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::getChildCount()` | Returns the number of direct children of the node with ID $nodeId.

#### getChildCountRecursive

int getChildCountRecursive( string $nodeId )

Returns the number of children of the node with ID $nodeId, recursively.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$nodeId` | string |

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::getChildCountRecursive()` | Returns the number of children of the node with ID $nodeId, recursively.

#### getPathLength

int getPathLength( string $nodeId )

Returns the distance from the root node to the node with ID $nodeId.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$nodeId` | string |

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::getPathLength()` | Returns the distance from the root node to the node with ID $nodeId.

#### getRootNode

ezcTreeNode getRootNode( )

Returns the root node.

This methods returns null if there is no root node.

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::getRootNode()` | Returns the root node.

#### hasChildNodes

bool hasChildNodes( string $nodeId )

Returns whether the node with ID $nodeId has children.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$nodeId` | string |

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::hasChildNodes()` | Returns whether the node with ID $nodeId has children.

#### isChildOf

bool isChildOf( string $childId , string $parentId )

Returns whether the node with ID $childId is a direct child of the node with ID $parentId.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$childId` | string |
`$parentId` | string |

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::isChildOf()` | Returns whether the node with ID $childId is a direct child of the node with ID $parentId.

#### isDescendantOf

bool isDescendantOf( string $childId , string $parentId )

Returns whether the node with ID $childId is a direct or indirect child of the node with ID $parentId.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$childId` | string |
`$parentId` | string |

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::isDescendantOf()` | Returns whether the node with ID $childId is a direct or indirect child of the node with ID $parentId.

#### isSiblingOf

bool isSiblingOf( string $child1Id , string $child2Id )

Returns whether the nodes with IDs $child1Id and $child2Id are siblings (ie, they share the same parent).

##### Parameters:

Name | Type | Description
--- | --- | ---
`$child1Id` | string |
`$child2Id` | string |

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::isSiblingOf()` | Returns whether the nodes with IDs $child1Id and $child2Id are siblings (ie, they share the same parent).

#### move

void move( string $nodeId , string $targetParentId )

Moves the node with ID $nodeId as child to the node with ID $targetParentId.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$nodeId` | string |
`$targetParentId` | string |

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::move()` | Moves the node with ID $nodeId as child to the node with ID $targetParentId.

#### nodeExists

bool nodeExists( string $nodeId )

Returns whether the node with ID $nodeId exists.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$nodeId` | string |

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::nodeExists()` | Returns whether the node with ID $nodeId exists.

#### saveFile

void saveFile( )

Saves the internal DOM representation of the tree back to disk.

#### setRootNode

void setRootNode( ezcTreeNode $node )

Sets a new node as root node, this also wipes out the whole tree.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$node` | ezcTreeNode |

##### Redefinition of:

Method | Description
--- | ---
`ezcTree::setRootNode()` | Sets a new node as root node, this also wipes out the whole tree.

Documentation generated by phpDocumentor 1.4.3