Checks that $document has a BODY element and adds it if it is missing.

@param \DOMDocument $document
972475
private function ensureExistenceOfBodyElement(\DOMDocument $document)
    {
        if ($document->getElementsByTagName('body')->item(0) !== null) {
            return;
        }

        $htmlElement = $document->getElementsByTagName('html')->item(0);

        $htmlElement->appendChild($document->createElement('body'));
    }
1267675
protected function encodeLiteral(DOMDocument $document)
    {
        $xpath = new DOMXPath($document);

        $xpathExpression = '//literal[not(@class="html")]';

        $elements = $xpath->query($xpathExpression);

        foreach ($elements as $element) {
            $element->textContent = str_replace(']]>', ']]]]><![CDATA[>', $element->textContent);
        }
    }
622549
protected function processTemplate(DOMDocument $document, DOMElement $template)
    {
        $content = null;
        $templateName = $template->getAttribute('name');
        $templateType = $template->hasAttribute('type') ? $template->getAttribute('type') : 'tag';
        $parameters = array(
            'name' => $templateName,
            'params' => $this->extractConfiguration($template),
        );

        if ($template->getElementsByTagName('ezcontent')->length > 0) {
            $contentNode = $template->getElementsByTagName('ezcontent')->item(0);
            switch ($templateType) {
                case 'style':
                    $parameters['content'] = $this->getCustomStyleContent($contentNode);
                    break;
                case 'tag':
                default:
                    $parameters['content'] = $this->getCustomTagContent($contentNode);
                    break;
            }
        }

        if ($template->hasAttribute('ezxhtml:align')) {
            $parameters['align'] = $template->getAttribute('ezxhtml:align');
        }

        $content = $this->renderer->renderTemplate(
            $templateName,
            $templateType,
            $parameters,
            $template->localName === 'eztemplateinline'
        );

        if (isset($content)) {
            // If current tag is wrapped inside another template tag we can't use CDATA section
            // for its content as these can't be nested.
            // CDATA section will be used only for content of root wrapping tag, content of tags
            // inside it will be added as XML fragments.
            if ($this->isWrapped($template)) {
                $fragment = $document->createDocumentFragment();
                $fragment->appendXML($content);
                $template->parentNode->replaceChild($fragment, $template);
            } else {
                $payload = $document->createElement('ezpayload');
                $payload->appendChild($document->createCDATASection($content));
                $template->appendChild($payload);
            }
        }
    }
1209295
public function insert($document): ?PostInsertId
    {
        /** @var DocumentMetadata $class */
        $class = $this->dm->getClassMetadata(get_class($document));
        $idGenerator = $this->dm->getUnitOfWork()->getIdGenerator($class->idGeneratorType);
        $postIdGenerator = $idGenerator->isPostInsertGenerator();

        $id = $postIdGenerator ? null : $class->getSingleIdentifier($document);
        $body = $this->prepareUpdateData($document)['body'];

        $response = $this->collection->create($id, $body);
        $data = $response->getData();

        foreach ($class->attributesMetadata as $field) {
            if (! $field instanceof FieldMetadata) {
                continue;
            }

            if ($field->indexName) {
                $field->setValue($document, $data['_index'] ?? null);
            }

            if ($field->typeName) {
                $field->setValue($document, $data['_type'] ?? null);
            }
        }

        $postInsertId = null;
        if ($postIdGenerator) {
            $postInsertId = new PostInsertId($document, $this->collection->getLastInsertedId());
        }

        return $postInsertId;
    }
690672
public function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node): void
    {
        if (!($node instanceof FeedInterface) || is_null($node->getLanguage())) {
            return;
        }
        $rootElement->appendChild($document->createElement($this->getNodeName(), $node->getLanguage()));
    }
366985
public function setDocument($document)
	{
		if (is_string($document)) {
			$this->document = $document;
		} else if (is_resource($document)) {
			$this->addMultipart("document", $document);
			$this->document = "attach://document";
		} else if ($document instanceof InputFile) {
			$this->addMultipart("document", $document->getFile());
			$this->document = "attach://document";
		}
	}
558552
public static void setDocumentElement(final Document document, final Element element) {
        Element documentElement = document.getDocumentElement();
        if (documentElement != null) {
            document.removeChild(documentElement);
        }
        if (element != null) {
            if (element.getOwnerDocument().equals(document)) {
                document.appendChild(element);
                return;
            }
            Node node = document.adoptNode(element);
            document.appendChild(node);
        }
    }
1187134
private static function createTypeElement(\DOMDocument $document, $parentElement = null, $type)
    {
        if ($parentElement->parentNode === null) {
            $typeElement = $document->createElementNS(
                'https://github.com/RhubarbPHP/Rhubarb/blob/master/docs/simple-xml-transcoder.md',
                self::XMLNS . ':' . $type
            );
            $parentElement->appendChild($typeElement);
        } else {
            $parentElement->setAttribute(self::XMLNS . ':' . self::ATTR_TYPE, $type);
            $typeElement = $parentElement;
        }

        return $typeElement;
    }
1264218
public function addElement($element)
    {
        if ($this->processing === 'B') {
            $this->bodyElements[] = $element;
        } elseif ($this->processing === 'H') {
            $this->headerElements[] = $element;
        } elseif ($this->processing === 'F') {
            $this->footerElements[] = $element;
        }
    }
1373112
protected function addStyleElementToDocument(\DOMDocument $document, $css)
    {
        $styleElement = $document->createElement('style', $css);
        $styleAttribute = $document->createAttribute('type');
        $styleAttribute->value = 'text/css';
        $styleElement->appendChild($styleAttribute);

        $bodyElement = $this->getBodyElement($document);
        $bodyElement->appendChild($styleElement);
    }
1163126
protected function addToDocument($document)
    {
        parent::addToDocument($document);

        $this->getRangeKey()->getPropertyMetadata()->setValue(
            $document,
            $this->getRangeValue()
        );
    }
986805
public function convert(DOMDocument $document)
    {
        foreach ($this->converters as $converter) {
            $converter->convert($document);
        }

        return $document;
    }
388146
protected function importItems(\DOMDocument $xml)
    {
        foreach ($xml->documentElement->getElementsByTagName('item') as $item) {
            $dom = simplexml_import_dom($item);
            $this->addMenuItem($dom);
        }
    }
1177338
public function parseDocument(\DOMDocument $document)
    {
        foreach ($this->registry[DocumentExtension::class] as $extension) {
            $doc = $extension->parseDocument($this, $document);
            if ($doc) {
                return $doc;
            }
        }

        return null;
    }
586064
private function fillElement (DOMDocument $doc, DOMElement $parent, array $filler)
    {
        foreach ($filler as $name => $value) {
            if ($value instanceof DOMElement) {
                $element = $value;
            } else {
                $element = $doc->createElement($name);
                
                if (is_array($value)) {
                    $this->fillElement($doc, $element, $value);
                } else {
                    $element->appendChild(new DOMCdataSection($value));
                }
            }
            
            $parent->appendChild($element);
        }
    }
1255466
public function process(\DOMDocument $xml)
    {
        $ignoreQry = '//tag[@name=\'' . $this->tag . '\']';

        $xpath = new \DOMXPath($xml);
        $nodes = $xpath->query($ignoreQry);

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

            // sometimes the parent node of the entity-to-be-removed is already
            // gone; for instance when a File docblock contains an @internal and
            // the underlying class also contains an @internal.
            // Because the File Docblock is found sooner, it is removed first.
            // Without the following check the application would fatal since
            // it cannot find, and then remove, this node from the parent.
            if (!isset($remove->parentNode)) {
                continue;
            }

            $remove->parentNode->removeChild($remove);
        }

        return $xml;
    }
450082
private function loadStructure(Document $dom)
    {
        $elementtypeStructure = new ElementtypeStructure();

        $nodes = $dom->documentElement->evaluate('structure/node');
        if ($nodes->length) {
            foreach ($nodes as $node) {
                $this->loadNode($node, $elementtypeStructure);
            }
        }

        return $elementtypeStructure;
    }