/** * @param Element $element * @return \DOMElement */ protected function createElement(Element $element) { $dom = $this->doc->createElement($element->getName(), $element->getValue()); foreach ($element->getAttributes() as $attribute) { $dom->setAttribute($attribute->getName(), $attribute->getValue()); } foreach ($element->getChildren() as $child) { $child = $this->createElement($child); $dom->appendChild($child); } return $this->doc->appendChild($dom); }
/** * @return $this|Element */ public function getRoot() { if ($this->parent = null) { return $this; } else { return $this->parent->getRoot(); } }
protected function parseElement($tag, array $description = array()) { $text = null; $children = array(); $attributes = array(); foreach ($description as $key => $value) { $type = $this->determineType($key, $value); switch ($type) { case self::ELEMENT: $children[] = $this->parseElement($key, $value); break; case self::ATTRIBUTE: $attributes = array_merge($attributes, $this->parseAttributes($value)); break; case self::TEXT: $text = $value; break; } } $element = new Element($tag, $text); $element->addAttributes($attributes); $element->appendChildren($children); return $element; }