public function addChild($name, $value = null) { if ($name instanceof XmlElementInterface) { $value = $name; $name = $value->getName(); } $coreElement = $this->elem->addChild($name); $element = new XmlElement($coreElement); if ($value instanceof XmlElementInterface) { foreach ($value->attributes() as $k => $v) { $element->attributes()->set($k, $v); } foreach ($value->children() as $child) { $element->addChild($child); } if ($value->text()) { $element->setText($value->text()); } $value->_swapoutInternal($coreElement); } else { $element->setText($value); } return $element; }