// returns the next sibling of node
function next_sibling() {
if ($this->parent===null) return null;
$idx = 0;
$count = count($this->parent->children);
while ($idx<$count && $this!==$this->parent->children[$idx])
++$idx;
if (++$idx>=$count) return null;
return $this->parent->children[$idx];
}
// returns the previous sibling of node
function prev_sibling() {
if ($this->parent===null) return null;
$idx = 0;
$count = count($this->parent->children);
while ($idx<$count && $this!==$this->parent->children[$idx])
++$idx;
if (--$idx<0) return null;
return $this->parent->children[$idx];
}
// get dom node's inner html
function innertext() {
if (isset($this->_[HDOM_INFO_INNER])) return $this->_[HDOM_INFO_INNER];
if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
$ret = '';
foreach($this->nodes as $n)
$ret .= $n->outertext();
return $ret;
}
// get dom node's outer text (with tag)
function outertext() {
if ($this->tag==='root') return $this->innertext();
// trigger callback
if ($this->dom->callback!==null)
call_user_func_array($this->dom->callback, array($this));
if (isset($this->_[HDOM_INFO_OUTER])) return $this->_[HDOM_INFO_OUTER];
if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
// render begin tag
$ret = $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]]->makeup();
// render inner text
if (isset($this->_[HDOM_INFO_INNER]))
$ret .= $this->_[HDOM_INFO_INNER];
else {
foreach($this->nodes as $n)
$ret .= $n->outertext();
}
// render end tag
if(isset($this->_[HDOM_INFO_END]) && $this->_[HDOM_INFO_END]!=0)
$ret .= '</'.$this->tag.'>';
return $ret;
}
// get dom node's plain text
function text() {
if (isset($this->_[HDOM_INFO_INNER])) return $this->_[HDOM_INFO_INNER];
switch ($this->nodetype) {
case HDOM_TYPE_TEXT: return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
case HDOM_TYPE_COMMENT: return '';
case HDOM_TYPE_UNKNOWN: return '';
}
if (strcasecmp($this->tag, 'script')===0) return '';
if (strcasecmp($this->tag, 'style')===0) return '';
$ret = '';
foreach($this->nodes as $n)
$ret .= $n->text();
return $ret;
}
function xmltext() {
$ret = $this->innertext();
$ret = str_ireplace('<![CDATA[', '', $ret);
$ret = str_replace(']]>', '', $ret);
return $ret;
}