ILIAS
Release_4_1_x_branch Revision 61804
|
domxml wrapper class This class provides some more complex methods to access a domDocument via DOMXML. More...
Public Member Functions | |
ilDOMXML () | |
Constructor init domxml handler You may (a) initiate this class with an existing domDocument OR (b) create a new domDocument depending on the parameters you pass to this constructor: | |
_ilDOMXML () | |
initNewDocument ($a_version="", $a_encoding="", $a_charset="") | |
init new domDocument private method. | |
createRootElement ($a_element) | |
wrapper for crating a root element this methods avoids creating multiple elements on root level. | |
loadDocument ($a_filename, $a_filepath, $a_validate=false) | |
loads a xml-document from file and build a DOM representation in $this->doc. | |
trim ($a_node) | |
traverse domDocument and removes all useless nodes that are created due to whitespaces in the source file | |
trimDocument ($a_node= '') | |
wrapper for $this->trim defaults to $this->doc if no node given and returns cleaned dom document | |
transform ($node, $left2=-1, $lvl=0) | |
traverse the domDocument and build a tree which contains additional information about domDocument's structure: $arr[id] = array( content (str) = node_value (only text nodes have a value) name (str) = tagname or entityname type (int) = element_type_id depth (int) = depth of node in tree parent (int) = id of parent node first (int) = id of first child node prev (int) = id of previous sibling node next (int) = id of next sibling node left (int) = left value (for traversing tree in relational DB) right (int) = right value (for traversing tree in relational DB)) The key is the internal id of the domDocument. | |
buildTree ($a_node="") | |
wrapper for $this->transform defaults to $this->doc if no node given and returns $this->tree | |
dumpDocument ($a_stdout=-1, $a_compress=false, $a_format=false) | |
wrapper for dump_mem() and dump_file() converts the entire DOM tree in $this->doc to a string optional: writes the string to a file if path & filename is specified. | |
getTextFromElement ($a_element) | |
fetch all text parts from an element even when the text is interupted by another element example: <paragraph>This text ispart of the same element. | |
isLeafElement ($a_node, $a_elementname, $a_num=0) | |
find leaf elements. | |
getElementsByTagname ($a_elementname, $a_node="") | |
wrapper for get_elements_by_tagname searches domDocument for specified elementname, starting at $a_node. | |
appendReferenceNodeForLO ($a_node, $a_lo_id, $a_lm_id, $a_prev_sibling) | |
creates an element entry for the removed LearningObject: <LO id=[obj_id of child LO] /> | |
appendChild ($a_node) | |
wrapper for append_child Main purpose of this method is to simplify access of DOM-Functions. | |
getRoot () | |
wrapper for document_element Main purpose of this method is to simplify access of DOM-Functions. | |
createElement ($a_node) | |
wrapper for create_element Main purpose of this method is to simplify access of DOM-Functions. | |
addElement ($a_parent, $a_node) | |
createText ($a_text) | |
wrapper for create_element Main purpose of this method is to simplify access of DOM-Functions. | |
createNode ($a_parent, $a_elementname, $a_attr_list=NULL, $a_text=NULL) | |
creates a complete node of type element with a text_node within the element and attributes The node is append to domDocument under the given parent_node | |
getElementId ($a_node) | |
get internal reference id of a domNode | |
getElementName ($a_node) | |
get node_name | |
setEncoding ($a_encode, $a_overwrite=false) | |
set encoding of domDocument | |
getEncoding () | |
get encoding of domDocument | |
setCharset ($a_charset, $a_overwrite=false) | |
set charset of domDocument | |
getCharset () | |
get charset of domDocument | |
getInfo () | |
fetch Title & Description from MetaData-Section of domDocument | |
getReferences () | |
get all LO references in Learning Object |
Data Fields | |
$doc | |
$tree | |
$error |
domxml wrapper class This class provides some more complex methods to access a domDocument via DOMXML.
For basic tasks when building xml-documents please use the standard functions from the domxml extension of PHP
Definition at line 15 of file class.ilDOMXML.php.
ilDOMXML::_ilDOMXML | ( | ) |
Definition at line 73 of file class.ilDOMXML.php.
ilDOMXML::addElement | ( | $a_parent, | |
$a_node | |||
) |
Definition at line 525 of file class.ilDOMXML.php.
ilDOMXML::appendChild | ( | $a_node | ) |
wrapper for append_child Main purpose of this method is to simplify access of DOM-Functions.
object | domNode |
Definition at line 495 of file class.ilDOMXML.php.
Referenced by createRootElement().
ilDOMXML::appendReferenceNodeForLO | ( | $a_node, | |
$a_lo_id, | |||
$a_lm_id, | |||
$a_prev_sibling | |||
) |
creates an element entry for the removed LearningObject: <LO id=[obj_id of child LO] />
object | domNode |
integer | object_id of removed LO public |
TODO: Moved this method to class where it fits better (LearningObject? xml2sql?)
Definition at line 470 of file class.ilDOMXML.php.
References createElement().
ilDOMXML::buildTree | ( | $a_node = "" | ) |
wrapper for $this->transform defaults to $this->doc if no node given and returns $this->tree
object | domNode |
Definition at line 344 of file class.ilDOMXML.php.
References $doc, $tree, and transform().
ilDOMXML::createElement | ( | $a_node | ) |
wrapper for create_element Main purpose of this method is to simplify access of DOM-Functions.
object | domNode |
Definition at line 520 of file class.ilDOMXML.php.
Referenced by appendReferenceNodeForLO(), createNode(), and createRootElement().
ilDOMXML::createNode | ( | $a_parent, | |
$a_elementname, | |||
$a_attr_list = NULL , |
|||
$a_text = NULL |
|||
) |
creates a complete node of type element with a text_node within the element and attributes The node is append to domDocument under the given parent_node
object | domNode the place where the new created node will be inserted |
string | name of the element |
array | list of attributes (optional). syntax: $arr["attr_name"] = attr_value |
string | if any text is given a text_node will be created (optional). |
Definition at line 558 of file class.ilDOMXML.php.
References createElement().
ilDOMXML::createRootElement | ( | $a_element | ) |
wrapper for crating a root element this methods avoids creating multiple elements on root level.
This is necessary since PHP crashes if you try to create another element on top level of domDocument :-(
string | taggname of root element public |
Definition at line 131 of file class.ilDOMXML.php.
References appendChild(), createElement(), and getRoot().
ilDOMXML::createText | ( | $a_text | ) |
wrapper for create_element Main purpose of this method is to simplify access of DOM-Functions.
object | domNode |
Definition at line 541 of file class.ilDOMXML.php.
ilDOMXML::dumpDocument | ( | $a_stdout = -1 , |
|
$a_compress = false , |
|||
$a_format = false |
|||
) |
wrapper for dump_mem() and dump_file() converts the entire DOM tree in $this->doc to a string optional: writes the string to a file if path & filename is specified.
Otherwise only the string is returned.
string | path/filename |
boolean | compress XML content |
boolean | format XML content with whitespaces |
Definition at line 367 of file class.ilDOMXML.php.
ilDOMXML::getCharset | ( | ) |
get charset of domDocument
Definition at line 660 of file class.ilDOMXML.php.
ilDOMXML::getElementId | ( | $a_node | ) |
get internal reference id of a domNode
object | domNode |
Definition at line 589 of file class.ilDOMXML.php.
ilDOMXML::getElementName | ( | $a_node | ) |
get node_name
object | domNode |
Definition at line 602 of file class.ilDOMXML.php.
ilDOMXML::getElementsByTagname | ( | $a_elementname, | |
$a_node = "" |
|||
) |
wrapper for get_elements_by_tagname searches domDocument for specified elementname, starting at $a_node.
If no node was given searches the entire domDocument in $this->doc returns an array of all nodes found
string | tagname of element |
object | domNode where to start searching (optional) |
Definition at line 447 of file class.ilDOMXML.php.
References $doc.
Referenced by getInfo(), and getReferences().
ilDOMXML::getEncoding | ( | ) |
get encoding of domDocument
Definition at line 631 of file class.ilDOMXML.php.
ilDOMXML::getInfo | ( | ) |
fetch Title & Description from MetaData-Section of domDocument
Definition at line 671 of file class.ilDOMXML.php.
References getElementsByTagname().
ilDOMXML::getReferences | ( | ) |
get all LO references in Learning Object
Definition at line 712 of file class.ilDOMXML.php.
References getElementsByTagname().
ilDOMXML::getRoot | ( | ) |
wrapper for document_element Main purpose of this method is to simplify access of DOM-Functions.
Definition at line 507 of file class.ilDOMXML.php.
Referenced by createRootElement().
ilDOMXML::getTextFromElement | ( | $a_element | ) |
fetch all text parts from an element even when the text is interupted by another element example: <paragraph>This text ispart of the same element.
</paragraph> This method returns: This text is part of the same element.
object | dom node of type ELEMENT (id:1) |
Definition at line 388 of file class.ilDOMXML.php.
References trim().
ilDOMXML::ilDOMXML | ( | ) |
Constructor init domxml handler You may (a) initiate this class with an existing domDocument OR (b) create a new domDocument depending on the parameters you pass to this constructor:
(a) init existing domDocument
object | domDocument |
(b) init new domDocument
string | xml version (optional) |
string | encoding charset (optional) |
string | charset (optional) public |
Definition at line 58 of file class.ilDOMXML.php.
References initNewDocument().
ilDOMXML::initNewDocument | ( | $a_version = "" , |
|
$a_encoding = "" , |
|||
$a_charset = "" |
|||
) |
init new domDocument private method.
Please use constructor to init a new domDocument
string | xml version (default: 1.0) |
string | encoding charset (default: UTF-8) |
string | charset (default: UTF-8) private |
Definition at line 92 of file class.ilDOMXML.php.
References domxml_open_mem(), setCharset(), and setEncoding().
Referenced by ilDOMXML().
ilDOMXML::isLeafElement | ( | $a_node, | |
$a_elementname, | |||
$a_num = 0 |
|||
) |
find leaf elements.
In this context leaf elements are defined as elements that don't contain other elements of the same type!
object | domNode of type ELEMENT |
string | tagname your are looking for |
integer | auxilliary variable to avoid counting start node itself. must set to 1 for the first function call |
Definition at line 415 of file class.ilDOMXML.php.
ilDOMXML::loadDocument | ( | $a_filename, | |
$a_filepath, | |||
$a_validate = false |
|||
) |
loads a xml-document from file and build a DOM representation in $this->doc.
The xml-document is parsed automatically. You may also validate it against a DTD by setting the 3rd parameter to 'true'
string | filename |
string | filepath |
boolean | set mode: parsing (false,default) or validating (true) public |
Definition at line 152 of file class.ilDOMXML.php.
References $doc, $error, DOMXML_LOAD_PARSING, DOMXML_LOAD_VALIDATING, domxml_open_file(), exit, setCharset(), and setEncoding().
ilDOMXML::setCharset | ( | $a_charset, | |
$a_overwrite = false |
|||
) |
set charset of domDocument
string | charset |
boolean | overwrite existing charset (true) or not (false) |
Definition at line 644 of file class.ilDOMXML.php.
Referenced by initNewDocument(), and loadDocument().
ilDOMXML::setEncoding | ( | $a_encode, | |
$a_overwrite = false |
|||
) |
set encoding of domDocument
string | encoding charset |
boolean | overwrite existing encoding charset (true) or not (false) |
Definition at line 615 of file class.ilDOMXML.php.
Referenced by initNewDocument(), and loadDocument().
ilDOMXML::transform | ( | $node, | |
$left2 = -1 , |
|||
$lvl = 0 |
|||
) |
traverse the domDocument and build a tree which contains additional information about domDocument's structure: $arr[id] = array( content (str) = node_value (only text nodes have a value) name (str) = tagname or entityname type (int) = element_type_id depth (int) = depth of node in tree parent (int) = id of parent node first (int) = id of first child node prev (int) = id of previous sibling node next (int) = id of next sibling node left (int) = left value (for traversing tree in relational DB) right (int) = right value (for traversing tree in relational DB)) The key is the internal id of the domDocument.
Also the ids of other nodes are internal references. The array is written to $this->tree. Use $this->buildTree() to return the variable.
object | domNode |
integer | left value (optional; only needed for recursion)) |
integer | depth of node in tree (optional, default is 0) private |
Definition at line 246 of file class.ilDOMXML.php.
Referenced by buildTree().
ilDOMXML::trim | ( | $a_node | ) |
traverse domDocument and removes all useless nodes that are created due to whitespaces in the source file
object | domNode private |
Definition at line 190 of file class.ilDOMXML.php.
Referenced by getTextFromElement(), transform(), and trimDocument().
ilDOMXML::trimDocument | ( | $a_node = '' | ) |
wrapper for $this->trim defaults to $this->doc if no node given and returns cleaned dom document
object | domNode (optional) public |
Definition at line 215 of file class.ilDOMXML.php.
ilDOMXML::$doc |
Definition at line 23 of file class.ilDOMXML.php.
Referenced by buildTree(), getElementsByTagname(), loadDocument(), and trimDocument().
ilDOMXML::$error |
Definition at line 40 of file class.ilDOMXML.php.
Referenced by loadDocument().
ilDOMXML::$tree |
Definition at line 31 of file class.ilDOMXML.php.
Referenced by buildTree().