Exemplo n.º 1
0
 /**
  * Create node.
  *
  * @param  Node            $parent  Parent node.
  * @param \DOMElement|null $element DOM element.
  *
  * @since 1.0
  *
  * @throws \InvalidArgumentException If $element has invalid namespace.
  */
 public function __construct(Node $parent, \DOMElement $element = null)
 {
     if (null === $element) {
         $owner = $parent->getDomElement();
         $ns = $this->ns();
         $element = $owner->ownerDocument->createElementNS($ns, $this->getNodeName());
         $owner->appendChild($element);
     }
     parent::__construct($element, $parent);
 }
Exemplo n.º 2
0
 /**
  * Create document.
  *
  * @param Extensions        $extensions Extension registry.
  * @param \DOMDocument|null $document   Source document.
  *
  * @throws \InvalidArgumentException If $document root node has invalid name.
  *
  * @since 1.0
  */
 public function __construct(Extensions $extensions, \DOMDocument $document = null)
 {
     $this->extensions = $extensions;
     if (null === $document) {
         $document = new \DOMDocument('1.0', 'utf-8');
         $element = $document->createElementNS($this->ns(), $this->getRootNodeName());
         $namespaces = $this->getExtensions()->getNamespaces();
         foreach ($namespaces as $prefix => $namespace) {
             if ($namespace !== $this->ns()) {
                 $element->setAttributeNS(Atom::XMLNS, 'xmlns:' . $prefix, $namespace);
             }
         }
         $document->appendChild($element);
     } elseif ($this->getRootNodeName() !== $document->documentElement->localName) {
         throw new \InvalidArgumentException(sprintf('Unexpected root node "%s", expecting "%s"', $document->documentElement->localName, $this->getRootNodeName()));
     }
     parent::__construct($document->documentElement);
 }