/** * Add the node to a position under the tree * * @param \SimpleXmlElement|Element $node * @param Element $parent */ public function addChild($node, $parent = null) { if ($node instanceof \SimpleXmlElement) { $name = $node->getName(); $attributes = (array) $node->attributes(); $content = trim((string) $node); $element = new Element($name, $attributes, $content); if (!$this->tree) { $this->tree = $element; } else { if (!$parent) { $parent = $this->tree; } $parent->addChild($element); } // Add child elements recursive if ($node->count() > 0) { foreach ($node as $childNode) { $this->addChild($childNode, $element); } } } else { if ($node instanceof Element) { if (!$this->tree) { $this->tree = $node; } else { if (!$parent) { $parent = $this->tree; } $parent->addChild($node); } } } }
public function count() { echo "Called Count!\n"; return parent::count(); }