Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
class DOMTree {
3
  var $domelement;
4
  var $content;
5
 
6
  function DOMTree($domelement) {
7
    $this->domelement = $domelement;
8
    $this->content = $domelement->textContent;
9
  }
10
 
11
  function &document_element() {
12
    return $this;
13
  }
14
 
15
  function &first_child() {
16
    if ($this->domelement->firstChild) {
17
      $child =& new DOMTree($this->domelement->firstChild);
18
      return $child;
19
    } else {
20
      $null = false;
21
      return $null;
22
    };
23
  }
24
 
25
  function &from_DOMDocument($domdocument) {
26
    $tree =& new DOMTree($domdocument->documentElement);
27
    return $tree;
28
  }
29
 
30
  function get_attribute($name) {
31
    return $this->domelement->getAttribute($name);
32
  }
33
 
34
  function get_content() {
35
    return $this->domelement->textContent;
36
  }
37
 
38
  function has_attribute($name) {
39
    return $this->domelement->hasAttribute($name);
40
  }
41
 
42
  function &last_child() {
43
    $child =& $this->first_child();
44
 
45
    if ($child) {
46
      $sibling =& $child->next_sibling();
47
      while ($sibling) {
48
        $child =& $sibling;
49
        $sibling =& $child->next_sibling();
50
      };
51
    };
52
 
53
    return $child;
54
  }
55
 
56
  function &next_sibling() {
57
    if ($this->domelement->nextSibling) {
58
      $child =& new DOMTree($this->domelement->nextSibling);
59
      return $child;
60
    } else {
61
      $null = false;
62
      return $null;
63
    };
64
  }
65
 
66
  function node_type() {
67
    return $this->domelement->nodeType;
68
  }
69
 
70
  function &parent() {
71
    if ($this->domelement->parentNode) {
72
      $parent =& new DOMTree($this->domelement->parentNode);
73
      return $parent;
74
    } else {
75
      $null = false;
76
      return $null;
77
    };
78
  }
79
 
80
  function &previous_sibling() {
81
    if ($this->domelement->previousSibling) {
82
      $sibling =& new DOMTree($this->domelement->previousSibling);
83
      return $sibling;
84
    } else {
85
      $null = false;
86
      return $null;
87
    };
88
  }
89
 
90
  function tagname() {
91
    return $this->domelement->localName;
92
  }
93
}
94
?>