Create Atom document from XML DOM document.

@param Extensions   $extensions Extension registry.
@param \DOMDocument $document   Source document.

@return Document|null

@since 1.0
491171
public function parseDocument(Extensions $extensions, \DOMDocument $document)
    {
        if (AtomPub::NS === $document->documentElement->namespaceURI) {
            switch ($document->documentElement->localName) {
                case 'service':
                    // Node name already checked
                    return new ServiceDocument($extensions, $document);
                case 'categories':
                    // Node name already checked
                    return new CategoryDocument($extensions, $document);
            }
        }

        return null;
    }
820076
public static function fromExtension($extension)
	{
		$extension = strtolower($extension);

		return isset(static::$mimetypes[$extension])
			? static::$mimetypes[$extension]
			: null;
	}
1130946
private function createDocument(?string $version = null, ?string $encoding = null): \DOMDocument
    {
        $doc = new \DOMDocument($version ?: $this->defaultVersion, $encoding ?: $this->defaultEncoding);
        $doc->formatOutput = true;

        return $doc;
    }
873938
protected function mergeTypeExtensions(DocumentAST $document): DocumentAST
    {
        $document->objectTypeDefinitions()->each(
            function (ObjectTypeDefinitionNode $objectType) use ($document) {
                $name = $objectType->name->value;

                $objectType = $document
                    ->extensionsForType($name)
                    ->reduce(
                        function (ObjectTypeDefinitionNode $relatedObjectType, ObjectTypeExtensionNode $typeExtension): ObjectTypeDefinitionNode {
                            $relatedObjectType->fields = ASTHelper::mergeUniqueNodeList(
                                $relatedObjectType->fields,
                                $typeExtension->fields
                            );

                            return $relatedObjectType;
                        },
                        $objectType
                    );

                // Modify the original document by overwriting the definition with the merged one
                $document->setDefinition($objectType);
            }
        );

        return $document;
    }
981527
protected function createTreeNodeDOMElement( DOMDocument $domDocument, eZContentObjectTreeNode $node )
    {
        $nodeElement = $domDocument->createElement( 'Node' );

        // Set attributes.
        $nodeElement->setAttribute( 'nodeID', $node->attribute( 'node_id' ) );
        $nodeElement->setAttribute( 'parentID', $node->attribute( 'parent_node_id' ) );

        // Get child information.
        $conditions = array( 'Depth' => 1,
                             'DepthOperator' => 'eq' );
        $nodeElement->setAttribute( 'childCount', eZContentObjectTreeNode::subTreeCountByNodeID( $conditions, $node->attribute( 'node_id' ) ) );

        // Get child information for tree structure.
        $conditions['ClassFilterType'] = 'include';
        $conditions['ClassFilterArray'] = eZINI::instance( 'contentstructuremenu.ini' )->variable( 'TreeMenu', 'ShowClasses' );
        $nodeElement->setAttribute( 'childMenuCount', eZContentObjectTreeNode::subTreeCountByNodeID( $conditions, $node->attribute( 'node_id' ) ) );

        // Get access rights element.
        $nodeElement->appendChild( $this->createAccessDOMElement( $domDocument, $node ) );

        // Get object element.
        $nodeElement->appendChild( $this->createObjectDOMElement( $domDocument, $node->attribute( 'object' ) ) );

        return $nodeElement;
    }
654951
public function process(\DOMDocument $xml)
    {
        $xpath = new \DOMXPath($xml);
        $nodes = $xpath->query(
            '/project/file/class/docblock/tag[@name="method"]'
        );

        /** @var \DOMElement $node */
        foreach ($nodes as $node) {
            $class = $node->parentNode->parentNode;

            $method = new \DOMElement('method');
            $class->appendChild($method);

            // set basic information
            $method->setAttribute('final', 'false');
            $method->setAttribute('static', 'false');
            $method->setAttribute('visibility', 'public');
            $method->setAttribute('line', $node->getAttribute('line'));
            $method->appendChild(
                new \DOMElement('name', $node->getAttribute('method_name'))
            );

            // fill docblock
            $docblock = new \DOMElement('docblock');
            $method->appendChild($docblock);
            $docblock->appendChild(
                new \DOMElement('description', $node->getAttribute('description'))
            );
            $docblock->appendChild(new \DOMElement('long-description'));

            // for each argument; create an @param tag and an argument element
            /** @var \DOMElement $argument */
            foreach ($node->getElementsByTagName('argument') as $argument) {
                $param_tag = new \DOMElement('tag');
                $docblock->appendChild($param_tag);
                $param_tag->setAttribute('name', 'param');
                $param_tag->setAttribute(
                    'type',
                    $argument->getElementsByTagName('type')->item(0)->nodeValue
                );
                $param_tag->setAttribute(
                    'variable',
                    $argument->getElementsByTagName('name')->item(0)->nodeValue
                );
                $param_tag->setAttribute('line', $node->getAttribute('line'));

                $types = explode(
                    '|',
                    $argument->getElementsByTagName('type')->item(0)->nodeValue
                );

                foreach ($types as $type) {
                    $type_element = new \DOMElement('type', $type);
                    $param_tag->appendChild($type_element);
                }

                $argument_element = $argument->cloneNode(true);
                $method->appendChild($argument_element);
            }

            // add a tag 'magic'
            $magic_tag = new \DOMElement('tag');
            $docblock->appendChild($magic_tag);
            $magic_tag->setAttribute('name', 'magic');
            $magic_tag->setAttribute('line', $node->getAttribute('line'));

            // add a @return tag
            $return_tag = new \DOMElement('tag');
            $docblock->appendChild($return_tag);
            $return_tag->setAttribute('name', 'return');
            $return_tag->setAttribute('line', $node->getAttribute('line'));
            $return_tag->setAttribute('type', $node->getAttribute('type'));

            // add type sub elements to the param
            foreach (explode('|', $node->getAttribute('type')) as $type) {
                $type_element = new \DOMElement('type', $type);
                $return_tag->appendChild($type_element);
            }

            // remove the tag, it is unneeded
            $node->parentNode->removeChild($node);
            $docblock->appendChild($node);
        }

        return $xml;
    }
359247
public static Document createDOMDocument()
    {
        try {
            return DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
        } catch (ParserConfigurationException ex) {
            LOGGER.error("Cannot create DOM Documents", ex);
            return null;
        }
    }
165248
public function format(\DOMDocument $document) : \DOMDocument
    {
        $element = $document->createElement('feed');
        $element->setAttribute('xmlns', 'http://www.w3.org/2005/Atom');
        $document->appendChild($element);

        return $document;
    }
419989
private function createMetadataNode(\DOMDocument $document, string $type = null): \DOMNode
    {
        $node = $document->createElement('object');
        if (null !== $type) {
            $node->setAttribute('type', $type);
        }

        return $node;
    }
336070
private function importXml(\DOMDocument $doc)
    {
        $importNodes=$doc->getElementsByTagName("import");
        for($i=$importNodes->length-1;$i>=0;$i--){
            $node = $importNodes->item($i);
            if($node->hasAttribute("file")){
                $file=$node->getAttribute("file");
                $path=rtrim(dirname($this->m_configFile),"/");
                $file=$path."/".ltrim($file,"/");
                if(file_exists($file)){
                    $_doc=new \DOMDocument();
                    $_doc->load($file);
                    $this->importXml($_doc);
                    $children=$_doc->documentElement->childNodes;
                    for($j=0;$j<$children->length;$j++){
                        $_node=$children->item($j);
                        if(is_a($_node,"DOMElement")){
                            $_node = $doc->importNode($_node, true);
                            $node->parentNode->insertBefore($_node,$node);
                        }
                    }
                    if(!in_array($file, $this->m_configFiles)){
                        $this->m_configFiles[]=$file;
                    }
                }
            }
            $node->parentNode->removeChild($node);
        }
    }
1042209
public void fromXML(Document domdoc) throws DocumentException
    {
        this.encoding = domdoc.getXMLEncoding();

        Element rootElement = domdoc.getRootElement();

        this.reference = readDocumentReference(domdoc);

        this.locale = rootElement.attributeValue("locale");
        if (this.locale == null) {
            // Fallback on old <language> element
            this.locale = readElement(rootElement, "language");
        }

        this.defaultLanguage = readElement(rootElement, "defaultLanguage");
        this.creator = readElement(rootElement, "creator");
        this.author = readElement(rootElement, AUTHOR_TAG);
        this.contentAuthor = readElement(rootElement, "contentAuthor");
        this.version = readElement(rootElement, "version");
        this.parent = readElement(rootElement, "parent");
        this.comment = readElement(rootElement, "comment");
        this.minorEdit = readElement(rootElement, "minorEdit");
        this.attachmentData = readAttachmentData(rootElement);
        this.isHidden = Boolean.parseBoolean(readElement(rootElement, "hidden"));
        this.title = readElement(rootElement, "title");
        this.syntaxId = readElement(rootElement, "syntaxId");
        this.content = readElement(rootElement, "content");

        this.datePresent = isElementPresent(rootElement, "date");
        this.contentUpdateDatePresent = isElementPresent(rootElement, "contentUpdateDate");
        this.creationDatePresent = isElementPresent(rootElement, "creationDate");
        this.attachmentDatePresent = rootElement.selectSingleNode("//attachment/date") != null;

        // Does this document contain a XWiki.TranslationDocumentClass xobject?
        if (!rootElement.selectNodes("//object/className[text() = 'XWiki.TranslationDocumentClass']").isEmpty()) {
            this.containsTranslations = true;
            // Record the visibility
            for (Node node : rootElement
                .selectNodes("//object/className[text() = 'XWiki.TranslationDocumentClass']/../property/scope")) {
                this.translationVisibilities.add(node.getStringValue());
            }
        }
    }
920597
protected function asXml(DomDocument $document)
    {
        $root = $document->createElement($this->getTagName(), $this->content);
        $document->appendChild($root);

        foreach ($this->attributes as $name => $value) {
            $root->setAttribute($name, $value);
        }

        foreach ($this->children as $child) {
            $root->appendChild($child->asXml($document));
        }

        return $root;
    }
872214
public function addExtension($extension = null)
    {
        if ($extension == null) {
            return $this->twigEnvironment->addExtension($this->twigDebug());
        }

        return $this->twigEnvironment->addExtension($extension);
    }
69865
private function extractShortText(DOMDocument $document)
    {
        $result = null;
        if ($section = $document->documentElement->firstChild) {
            $textDom = $section->firstChild;

            if ($textDom && $textDom->hasChildNodes()) {
                $result = $textDom->firstChild->textContent;
            } elseif ($textDom) {
                $result = $textDom->textContent;
            }
        }

        if ($result === null) {
            $result = $document->documentElement->textContent;
        }

        return trim($result);
    }
454806
public function withExtensionRequest(Extensions $extensions): self
    {
        $obj = clone $this;
        if (!isset($obj->_attributes)) {
            $obj->_attributes = new Attributes();
        }
        $obj->_attributes = $obj->_attributes->withUnique(
            Attribute::fromAttributeValues(
                new ExtensionRequestValue($extensions)));
        return $obj;
    }
164493
protected function documentFragmentCreate($source, $charset = null)
    {
        $fake              = new DOMDocumentWrapper();
        $fake->contentType = $this->contentType;
        $fake->isXML       = $this->isXML;
        $fake->isHTML      = $this->isHTML;
        $fake->isXHTML     = $this->isXHTML;
        $fake->root        = $fake->document;
        if (!$charset) {
            $charset = $this->charset;
        }
        //	$fake->documentCreate($this->charset);
        if ($source instanceof DOMNODE && !($source instanceof DOMNODELIST)) {
            $source = array($source);
        }
        if (is_array($source) || $source instanceof DOMNODELIST) {
            // dom nodes
            // load fake document
            if (!$this->documentFragmentLoadMarkup($fake, $charset)) {
                return false;
            }
            $nodes = $fake->import($source);
            foreach ($nodes as $node)
                $fake->root->appendChild($node);
        } else {
            // string markup
            $this->documentFragmentLoadMarkup($fake, $charset, $source);
        }

        return $fake;
    }
443229
public static function createXmlDocumentFromFile($filename, $docOptions = XMLUTIL_OPT_DONT_FIX_AMPERSAND)
    {
        if (!file_exists($filename)) {
            throw new XmlUtilException("Xml document $filename not found.", 250);
        }
        $xml = file_get_contents($filename);
        $xmldoc = self::createXmlDocumentFromStr($xml, $docOptions);
        return $xmldoc;
    }