Extract HTML from XHTML container.

@param \DOMElement $element

@return string

@since 1.0
434754
public static function extract(\DOMElement $element)
    {
        $doc = new \DOMDocument('1.0', 'utf-8');
        $imported = $doc->importNode($element, true);
        $doc->appendChild($imported);

        $prefix = $doc->lookupPrefix('http://www.w3.org/1999/xhtml');
        if ('' !== $prefix) {
            $prefix .= ':';
        }
        $patterns = [
            '/<\?xml[^<]*>[^<]*<' . $prefix . 'div[^<]*/',
            '/<\/' . $prefix . 'div>\s*$/'
        ];
        $text = preg_replace($patterns, '', $doc->saveXML());
        if ('' !== $prefix) {
            $text = preg_replace('/(<[\/]?)' . $prefix . '([a-zA-Z]+)/', '$1$2', $text);
        }

        return $text;
    }
800688
public function toXML(DOMElement $parent = null) : DOMElement
    {
        $element = parent::toXML($parent);

        if ($this->Format !== null) {
            $element->setAttribute('Format', $this->Format);
        }

        if ($this->SPProvidedID !== null) {
            $element->setAttribute('SPProvidedID', $this->SPProvidedID);
        }

        $value = $element->ownerDocument->createTextNode($this->value);
        $element->appendChild($value);

        return $element;
    }
482928
protected function getValueFromElement(DOMElement $element)
	{
		return (!$element->attributes->length && $element->childNodes->length === 1 && $element->firstChild->nodeType === XML_TEXT_NODE)
		     ? $element->nodeValue
		     : $this->getElementConfig($element);
	}
257994
protected function getElementAttribute(DomElement $element, $attributeName)
    {
        // First try to return for link
        if ($element->localName === 'link') {
            return $element->getAttribute($attributeName);
        }

        // Second return for embed
        return $element->getAttribute(EmbedLinking::TEMP_PREFIX . $attributeName);
    }
1167744
public function _getElementHtml(
        \Magento\Framework\Data\Form\Element\AbstractElement $element
    ) {
        $originalData = $element->getOriginalData();
        $buttonLabel = !empty($originalData['button_label'])
            ? $originalData['button_label'] : $this->buttonLabel;
        $url = $this->_urlBuilder->getUrl(
            'dotdigitalgroup_email/datafield/save',
            ['website_id' => $this->getRequest()->getParam('website', 0)]
        );
        $this->addData(
            [
                'button_label' => $buttonLabel,
                'html_id' => $element->getHtmlId(),
                'ajax_url' => $url,
            ]
        );

        return $this->_toHtml();
    }
395361
public function getAttributesForElement(Element $element) : string
    {
        $attributes = [];

        if ($this->usesTrait($element, Classable::class)) {
            $attributes[] = $element->renderClassAttribute();
        }

        if ($this->usesTrait($element, Spannable::class)) {
            $attributes[] = $element->renderSpanAttribute();
        }

        if ($this->usesTrait($element, Attributable::class)) {
            $attributes[] = $element->renderAttributes();
        }

        $attributes = array_filter($attributes);

        return $attributes ? ' ' . implode(' ', $attributes) : '';
    }
938355
public function getInlineStyles(\DOMElement $element)
    {
        $processor = new PropertyProcessor();

        return $processor->convertArrayToObjects(
            $processor->splitIntoSeparateProperties(
                $element->getAttribute('style')
            )
        );
    }
1025713
private function getFormNode(\DOMElement $element)
    {
        if ($element->hasAttribute('form')) {
            $formId = $element->getAttribute('form');
            $formNode = $element->ownerDocument->getElementById($formId);

            if (null === $formNode || 'form' !== $formNode->nodeName) {
                throw new DriverException(sprintf('The selected node has an invalid form attribute (%s).', $formId));
            }

            return $formNode;
        }

        $formNode = $element;

        do {
            // use the ancestor form element
            if (null === $formNode = $formNode->parentNode) {
                throw new DriverException('The selected node does not have a form ancestor.');
            }
        } while ('form' !== $formNode->nodeName);

        return $formNode;
    }
1071571
private function getFieldElement($element)
    {
        $element = $this->getElement($element);
        while (null !== $element && !$element->hasClass('field')) {
            $element = $element->getParent();
        }

        return $element;
    }
1197656
private function elementBodyAttr(string $element) : string
    {
        if (in_array($element, $this->body_elements) === true) {
            $attr = '';

            if (count($this->body_attr[$element]) > 0) {
                if (array_key_exists($element, $this->body_attr_first) === false) {
                    $attr = ' style="' . implode(' ', $this->body_attr[$element]) . '"';
                } else {
                    $attr = ' style="';
                    foreach ($this->body_attr[$element] as $body_attr) {
                        if (array_key_exists($body_attr, $this->body_attr_first[$element]) === false) {
                            $attr .= ' ' . $body_attr . ';';
                        } else {
                            if ($this->body_attr_first[$element][$body_attr] === true) {
                                $attr .= ' ' . $body_attr . ';';
                                $this->body_attr_first[$element][$body_attr] = false;
                            }
                        }
                    }
                    $attr .= '"';
                }
            }

            return $attr;
        } else {
            return '';
        }
    }
361266
protected function unmarshall(DOMElement $element)
    {
        $component = new Br();

        if (($xmlBase = self::getXmlBase($element)) !== false) {
            $component->setXmlBase($xmlBase);
        }

        $this->fillBodyElement($component, $element);

        return $component;
    }
1230996
private function mapNode(\DOMElement $element)
    {
        $attributes = [];

        $titles = [];
        $titlesElement = $element->getElementsByTagName('titles')->item(0);
        foreach ($titlesElement->getElementsByTagName('title') as $titleNode) {
            $titles[$titleNode->getAttribute('language')] = $titleNode->textContent;
        }

        $slugs = [];
        $slugsElement = $element->getElementsByTagName('slugs')->item(0);
        foreach ($slugsElement->getElementsByTagName('slug') as $slugNode) {
            $slugs[$slugNode->getAttribute('language')] = $slugNode->textContent;
        }

        $versions = [];
        $versionsElement = $element->getElementsByTagName('versions')->item(0);
        foreach ($versionsElement->getElementsByTagName('version') as $versionNode) {
            $versions[$versionNode->getAttribute('language')] = (int) $versionNode->textContent;
        }

        $node = new ContentTreeNode();
        $node
            ->setTree($this)
            ->setId((int) $element->getAttribute('id'))
            ->setParentNode($element->getAttribute('parentId') ? (int) $element->getAttribute('parentId') : null)
            ->setType((string) $element->getAttribute('type'))
            ->setTypeId((int) $element->getAttribute('typeId'))
            ->setAttributes($attributes)
            ->setSort((string) $element->getAttribute('sort'))
            ->setSortMode((string) $element->getAttribute('sortMode'))
            ->setSortDir((string) $element->getAttribute('sortDir'))
            ->setTitles($titles)
            ->setSlugs($slugs)
            //->setVersions($versions)
            ->setCreatedAt(new \DateTime((string) $element->getAttribute('createdAt')))
            ->setCreateUserId((string) $element->getAttribute('createUserId'));

        $this->nodes[$node->getId()] = $node;

        if ($node->getParentNode() === null) {
            $this->rootId = $node->getId();
        }

        return $node;
    }
464423
public function getElementHtml($element)
    {
        // Ensure we have an element type
        if (!isset($element->template) && empty($element->template)) {
            throw new Exception("Missing page element template");
        }

        return $this->container->view->fetch("elements/{$element->template}", ['element' => $element]);
    }
1216297
private function renderElementAsRow(Element $element) : string
    {
        $tr = new Tag('tr');

        $html = $this->renderCell('th', $element->getLabel()->render() . $this->renderErrors($element));
        $html .= $this->renderCell('td', $element->render());

        $tr->setHtmlContent($html);

        return $tr->render();
    }
273218
protected function replaceXslElement(DOMElement $element)
	{
		$elName = $this->lowercase($element->getAttribute('name'));
		$element->setAttribute('name', $elName);
	}
847792
protected function exportHtml(\DOMElement $element)
    {
        $body = $this->getDocument()->createElement('body');
        $body->appendChild($element);
        $html = $this->getDocument()->getElementsByTagName('html')->item(0);
        $html->appendChild($this->getHead());
        $html->appendChild($body);

        $html =  $this->getDocument()->saveHTML();
        $this->reset();

        return $html;
    }
772898
public function getNamespaces(\DOMElement $element = null)
    {
        if ($this->xpath === null) {
            $this->xpath = new \DOMXPath($this);
        }

        if ($element === null) {
            $nodes = $this->xpath->query('namespace::*');
        } else {
            $nodes = $this->xpath->query('namespace::*', $element);
        }

        $ns = array();

        if ($nodes) {
            foreach ($nodes as $node) {
                $arr = $element->getAttribute($node->nodeName);

                if ($arr) {
                    $ns[$node->nodeName] = $arr;
                }
            }

            $nodes = null;
        }

        return $ns;
    }