rendered paste body<?phpclass node{ public $namespace; public $tag; public $content; public $child; public $sibling; public function __construct($namespace, $tag, $content = null) { $this->namespace = $namespace; $this->tag = $tag; $this->content = $content; } public function add(node $node) { if($this->child) { for($c = $this->child; $c->sibling; $c = $c->sibling); $c->sibling = $node; } else { $this->child = $node; } } public function __toString() { $result = ''; $stack = array(); $cur = $this; while(1) { if($cur) { if($cur->child !== null || $cur->content !== null) { $result .= sprintf("<%s:%s>", $cur->namespace, $cur->tag, $cur->content); if($cur->content !== null) { $result .= sprintf("%s", $cur->content); } array_push($stack, $cur); $cur = $cur->child; } else { $result .= sprintf("<%s:%s />", $cur->namespace, $cur->tag); $cur = $cur->sibling; } } elseif($stack) { $cur = array_pop($stack); $result .= sprintf("</%s:%s>", $cur->namespace, $cur->tag); $cur = $cur->sibling; } else { break; } } return $result; }}?>