public function render($ret = false, $depth = 0, $indent = null)
{
// Initialize child object properties and variables.
$this->output = '';
$this->indent = null === $this->indent ? str_repeat(' ', $depth) : $this->indent;
$attribs = '';
$attribAry = array();
// Format child attributes, if applicable.
if (count($this->attributes) > 0) {
foreach ($this->attributes as $key => $value) {
$attribAry[] = $key . "=\"" . $value . "\"";
}
$attribs = ' ' . implode(' ', $attribAry);
}
// Initialize the node.
$this->output .= "{$indent}{$this->indent}<{$this->nodeName}{$attribs}";
if (null === $indent && null !== $this->indent) {
$indent = $this->indent;
$origIndent = $this->indent;
} else {
$origIndent = $indent . $this->indent;
}
// If current child element has child nodes, format and render.
if (count($this->childNodes) > 0) {
$this->output .= ">\n";
$new_depth = $depth + 1;
// Render node value before the child nodes.
if (!$this->childrenFirst) {
$this->output .= null !== $this->nodeValue ? str_repeat(' ', $new_depth) . "{$indent}{$this->nodeValue}\n" : '';
foreach ($this->childNodes as $child) {
$this->output .= $child->render(true, $new_depth, $indent);
}
$this->output .= "{$origIndent}</{$this->nodeName}>\n";
// Else, render child nodes first, then node value.
} else {
foreach ($this->childNodes as $child) {
$this->output .= $child->render(true, $new_depth, $indent);
}
$this->output .= null !== $this->nodeValue ? str_repeat(' ', $new_depth) . "{$indent}{$this->nodeValue}\n{$origIndent}</{$this->nodeName}>\n" : "{$origIndent}</{$this->nodeName}>\n";
}
// Else, render the child node.
} else {
if (null !== $this->nodeValue || $this->nodeName == 'textarea') {
$this->output .= ">";
$this->output .= "{$this->nodeValue}</{$this->nodeName}>\n";
} else {
$this->output .= " />\n";
}
}
// Return or print the rendered child node output.
if ($ret) {
return $this->output;
} else {
echo $this->output;
}
}