Exemplo n.º 1
0
 /**
  * setElementValue
  *
  * @param DOMDocument $dom
  * @param DOMElement $node
  * @param mixed $value
  *
  * @return null|bool returns false if no value was set, else null;
  */
 private function setElementValue(DOMDocument $dom, DOMElement $node, $value = null)
 {
     if ($value instanceof \SimpleXMLElement) {
         return $node->appendChild($dom->importNode(dom_import_simplexml($value), true));
     }
     if ($value instanceof \DOMDocument) {
         return $node->appendDomElement($value->firstChild);
     }
     if ($value instanceof \DOMElement) {
         return $dom->appendDomElement($value, $node);
     }
     if (is_array($value) || $value instanceof \Traversable) {
         return $this->buildXML($dom, $node, $value);
     }
     if (is_int($value) || is_float($value)) {
         return $this->createText($dom, $node, (string) $value);
     }
     if (is_bool($value)) {
         return $this->createText($dom, $node, $value ? 'true' : 'false');
     }
     if (is_string($value) || null === $value) {
         return $this->appendTextNode($dom, $node, (string) $value);
     }
     return false;
 }