/** * @param XmlElement $toAppend * @param boolean $root * @return void */ public function appendChild($toAppend, $root = false) { if ($root) { $node = $this->addChild($toAppend->getName()); foreach ($toAppend->attributes() as $key => $value) { $node->addAttribute($key, $value); } $node->appendChild($toAppend); } else { foreach ($toAppend as $name => $tree) { $child = $this->addChild($name, $this->_fixContent(strval($tree))); foreach ($tree->attributes() as $attrKey => $attrValue) { $child->addAttribute($attrKey, $attrValue); } $child->appendChild($tree->children()); } } }
/** * Append other XMLElement, support namespaces. * * @param XmlElement $append */ public function append($append) { //if ( $append ) not working for 'defs' if (isset($append)) { //list all namespaces used in append object $namespaces = $append->getNameSpaces(); //get all childs if (strlen(trim((string) $append)) == 0) { $xml = $this->addChild($append->getName()); foreach ($append->children() as $child) { $xml->append($child); } } else { //add one child $xml = $this->addChild($append->getName(), (string) $append); } //add simple attributes foreach ($append->attributes() as $attribute => $value) { $xml->addAttribute($attribute, $value); } //add attributes with namespace example xlink:href foreach ($namespaces as $index => $namespace) { foreach ($append->attributes($namespace) as $attribute => $value) { $xml->addAttribute($index . ':' . $attribute, $value, $namespace); } } } }