80 $num = func_num_args();
81 $args = func_get_args();
83 if (($num == 1) && is_object($args[0]))
85 $this->doc = $args[0];
97 printf(
"domxml destructor called, class=%s\n", get_class($this).
"<br/>");
119 $a_encoding =
"UTF-8";
123 $a_charset =
"UTF-8";
127 $xmlHeader =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>".
134 $root = $this->doc->document_element();
135 $root->unlink_node();
154 if ($root = $this->
getRoot()) {
175 $mode = DOMXML_LOAD_VALIDATING;
177 $mode = DOMXML_LOAD_PARSING;
180 $this->doc =
domxml_open_file($a_filepath .
"/" . $a_filename, $mode, $this->error);
184 $error_msg =
"Error(s) while parsing the document!<br><br>";
186 foreach ($this->error as
$error) {
187 $error_msg .= $error[
"errormessage"].
" in line: ".$error[
"line"].
"<br>";
212 if ($a_node->has_child_nodes()) {
213 $childs = $a_node->child_nodes();
215 foreach ($childs as $child) {
216 $content =
trim($child->get_content());
218 if (empty($content)) {
219 $child->unlink_node();
237 if (empty($a_node)) {
241 $this->
trim($a_node);
282 $node2 = (array)$node;
289 $this->tree[$node2[0]][
"struct"] = 0;
291 if ($parent = $node->parent_node()) {
292 $parent = (array)$parent;
295 if ($first = $node->first_child())
297 $first = (array)$first;
300 if ($prev = $node->previous_sibling()) {
301 $prev = (array)$prev;
304 if ($next = $node->next_sibling()) {
305 $next = (array)$next;
308 $this->tree[$node2[0]][
"content"] =
trim($node->node_value());
309 $this->tree[$node2[0]][
"name"] = $node->node_name();
310 $this->tree[$node2[0]][
"type"] = $node->type;
311 $this->tree[$node2[0]][
"depth"] = $lvl;
312 $this->tree[$node2[0]][
"parent"] = $parent[0];
313 $this->tree[$node2[0]][
"first"] = $first[0];
314 $this->tree[$node2[0]][
"prev"] = $prev[0];
315 $this->tree[$node2[0]][
"next"] = $next[0];
316 $this->tree[$node2[0]][
"left"] = $left;
320 if ($node->has_attributes())
324 foreach ($node->attributes() as $attribute)
326 $data[$attribute->name] = $attribute->value;
329 $this->tree[$node2[0]][
"attr_list"] =
$data;
330 $this->tree[$node2[0]][
"struct"] += 1;
334 foreach ($node->child_nodes() as $child)
336 if ($child->node_type() == XML_TEXT_NODE)
338 $this->tree[$node2[0]][
"struct"] += 2;
345 foreach ($node->child_nodes() as $child)
350 $this->tree[$node2[0]][
"right"] = $left;
366 if (empty($a_node)) {
387 function dumpDocument ($a_stdout = -1, $a_compress =
false, $a_format =
false)
389 if ($a_stdout != -1) {
390 $this->doc->dump_file($a_stdout,$a_compress,$a_format);
393 return $this->doc->dump_mem();
410 if ($a_element->node_type() == XML_ELEMENT_NODE) {
413 foreach ($a_element->child_nodes() as $child) {
414 if ($child->node_type() == XML_TEXT_NODE) {
415 $value .= $child->content;
422 die(
"<b>".$a_element.
"</b> is not a valid element node!");
439 if ($childs = $a_node->child_nodes()) {
440 foreach ($childs as $child) {
449 if (($a_node->node_type() == XML_ELEMENT_NODE) && ($a_node->tagname == $a_elementname) && ($a_num != 1)) {
469 if (empty($a_node)) {
473 if (count($node = $a_node->get_elements_by_tagname($a_elementname)) > 0) {
494 if (empty($a_prev_sibling))
496 $node = $a_node->append_child($newnode);
500 $node = $a_prev_sibling->append_sibling($newnode);
503 $node->set_attribute(
"id",$a_lo_id);
504 $node->set_attribute(
"lm",$a_lm_id);
517 return $this->doc->append_child($a_node);
529 return $this->doc->document_element();
542 return $this->doc->create_element($a_node);
547 $node = $this->doc->create_element($a_node);
548 $node = $a_parent->append_child($node);
563 return $this->doc->create_text_node($a_text);
578 function createNode ($a_parent, $a_elementname, $a_attr_list = NULL, $a_text = NULL)
584 if (is_array($a_attr_list)) {
585 foreach ($a_attr_list as $attr => $value) {
586 $node->set_attribute($attr, $value);
591 if (is_string($a_text)) {
592 $node_text = $this->doc->create_text_node($a_text);
593 $node_text = $node->append_child($node_text);
597 $node = $a_parent->append_child($node);
611 $node = (array) $a_node;
624 return $a_node->node_name();
637 if (empty($this->doc->encoding) or ($a_overwrite)) {
638 $this->doc->encoding = $a_encode;
653 return $this->doc->encoding;
666 if (is_integer($this->doc->charset) or ($a_overwrite)) {
667 $this->doc->charset = $a_charset;
682 return $this->doc->charset;
697 $childs = $node[0]->child_nodes();
699 foreach ($childs as $child)
701 if (($child->node_type() == XML_ELEMENT_NODE) && ($child->tagname ==
"General"))
703 $childs2 = $child->child_nodes();
705 foreach ($childs2 as $child2)
707 if (($child2->node_type() == XML_ELEMENT_NODE) && ($child2->tagname ==
"Title" || $child2->tagname ==
"Description"))
709 $arr[$child2->tagname] = $child2->get_content();
720 $arr[
"title"] = $arr[
"Title"];
721 $arr[
"desc"] = $arr[
"Description"];
736 foreach ($nodes as $node)
738 $attr[] = $node->get_attribute(
"id");