/** @test */ public function appendDomElementShouldThrowExceptionWithoutOwnerDocument() { $element = new DOMElement('foo'); try { $element->appendDomElement(new DOMElement('bar')); } catch (\BadMethodCallException $e) { $this->assertSame('cannot add an element without an owner document', $e->getMessage()); } catch (\Exception $e) { $this->fail($e->getMessage()); } }
/** * 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; }
/** * A lookahead to find sibling elements with similar names. * * @param DOMElement $node the node in charge. * @param string $prefix the element prefix * * @return \DOMNodeList */ private function getEqualNodes(DOMElement $node, $prefix = null) { $name = $this->prefixKey($node->nodeName, $prefix); return $node->xpath(sprintf(".|following-sibling::*[name() = '%s']|preceding-sibling::*[name() = '%s']", $name, $name)); }