Home » XML » XML_Tree » Manual
Build XML documents using a tree representation The XML_Tree package allows one to build XML data structures using a tree representation, without the need for an extension like DOMXML.
XML_Tree::XML_Tree
XML_Tree::XML_Tree – Constructor
Synopsis
require_once "XML/Tree.php";
void XML_Tree::XML_Tree (
string $filename=''
,
string $version='1.0'
)
Description
Constructor
Parameter
-
string $filename- name of the file to parse -
string $version- XML version to use
Note
This function can not be called statically.
XML_Tree::&addRoot
XML_Tree::&addRoot – add root node
Synopsis
require_once "XML/Tree.php";
object XML_Tree_Node XML_Tree::&addRoot (
string $name
,
string $content=''
,
array $attributes=array()
)
Description
Adds a new root node to the XML datastructure.
Parameter
-
string $name- name of root element -
string $content- data between the opening and closing tag -
array $attributes- additional attributes for the tag. The attribute name is represented as the array key and the attribute value as entry for the key.
Return value
object XML_Tree_Node - reference to root node
Note
This function can not be called statically.
Example
Using &addRoot()
<?php
$tree = new XML_Tree;
$root =& $tree->addRoot("root");
?>
XML_Tree::&insertChild
XML_Tree::&insertChild – inserts a child/tree
Synopsis
require_once "XML/Tree.php";
object XML_Tree_Node XML_Tree::&insertChild (
array $path
,
integer $pos
,
mixed $child
,
string $content=''
,
array $attributes=array()
)
Description
Inserts a child or tree into the tree in the path
$path on position $pos
and maintains namespace integrity
Parameter
-
array $path- path to parent of child to insert -
integer $pos- position of child to be inserted in its parent's children-list -
mixed $child- child-node (by XML_Tree, XML_Node or Name) -
string $content- content (text) for new node -
array $attributes- attribute-hash for new node
Return value
object XML_Tree_Node - inserted child (node)
Note
This function can not be called statically.
See
XML_Tree::&removeChild
XML_Tree::&removeChild – remove child from tree
Synopsis
require_once "XML/Tree.php";
object XML_Tree_Node XML_Tree::&removeChild (
array $path
,
integer $pos
)
Description
Removes a child ($path,$pos) from tree and maintains namespace integrity
Parameter
-
array $path- path to parent of child to remove -
integer $pos- position of child in parents children-list
Return value
object XML_Tree_Node - parent whichs child was removed
Note
This function can not be called statically.
See
XML_Tree::&getTreeFromFile
XML_Tree::&getTreeFromFile – map XML file to tree
Synopsis
require_once "XML/Tree.php";
object XML_Tree XML_Tree::&getTreeFromFile (
)
Description
Maps a XML file to an object tree
Return value
object XML_Tree - the object tree
Note
This function can not be called statically.
See
XML_Tree::clone
XML_Tree::clone – copy tree
Synopsis
require_once "XML/Tree.php";
object XML_Tree XML_Tree::clone (
)
Description
Get a copy of this tree instance.
Return value
object XML_Tree -
the copied object
Note
This function can not be called statically.
XML_Tree::dump
XML_Tree::dump – print XML tree.
Synopsis
require_once "XML/Tree.php";
void XML_Tree::dump (
)
Description
Print text representation of XML tree.
Note
This function can not be called statically.
See
XML_Tree::&get
XML_Tree::&get – get XML tree.
Synopsis
require_once "XML/Tree.php";
string XML_Tree::&get (
)
Description
Get text representation of XML tree.
Return value
string - XML document
Note
This function can not be called statically.
See
XML_Tree::&getName
XML_Tree::&getName – get namespace.
Synopsis
require_once "XML/Tree.php";
string XML_Tree::&getName (
string $name
)
Description
Get the current namespace.
Parameter
-
string $name- namespace
Return value
string - namespace
Note
This function can not be called statically.
See
XML_Tree::registerName
XML_Tree::registerName – register namespace.
Synopsis
require_once "XML/Tree.php";
void XML_Tree::registerName (
string $name
,
string $path
)
Description
Registers a namespace.
Parameter
-
string $name- namespace -
string $path- path
Note
This function can not be called statically.