@param string|\DOMNode $mixed

@return \SimpleXMLElement

@codeCoverageIgnore
184169
protected function _simpleXml($mixed): \SimpleXMLElement
    {
        if ($mixed instanceof \DOMNode) {
            return \simplexml_import_dom($mixed);
        }

        if (File::isFile($mixed))
        {
            $mixed = \file_get_contents($mixed);
        }

        return \simplexml_load_string($mixed);
    }
1259288
public function from($mixed)
    {
        if (is_object($mixed)) {
            return $mixed;
        }
        if (is_array($mixed)) {
            return $this->fromArray($mixed);
        }
        if (is_string($mixed)) {
            return $this->fromString($mixed);
        }
        if (is_null($mixed)) {
            return $this->fromString('/');
        }
    }
1124775
public function render(\DOMDocument $domDocument)
    {
        $container = new Frame();
        $container->setPosition($this->frame_posX, $this->frame_posY);

        $quad = new Quad();
        // this quad is used to placeholder, if you need to add later "frame"  to the view.

        $contentFrame = new Frame();
        $contentFrame->addChild($this->parentFrame);

        $container->addChild($quad);
        $container->addChild($contentFrame);
        if ($this->scrollbarV) {
            $contentFrame->setSize($this->width - 5, $this->height);
            $this->offset = 5;
            $container->addChild(new Scrollbar(
                "Y",
                $this->getWidth(),
                0,
                10,
                $this->getHeight()
            ));
        }

        if ($this->scrollbarH) {
            $contentFrame->setSize($this->width - 5, $this->height - 5);
            $container->addChild(new Scrollbar(
                "X",
                0,
                -$this->getHeight(),
                10,
                $this->getWidth() - $this->offset
            ));
        }


        return $container->render($domDocument);
    }
1318471
private static function convertHtmlToDom($html)
    {
        $dom = new DOMDocument;

        \libxml_use_internal_errors(true);
        $dom->loadHTML($html);

        \libxml_clear_errors();

        return $dom;
    }
155137
public static function toArray($obj)
    {
        if ($obj instanceof DOMNode) {
            $obj = simplexml_import_dom($obj);
        }
        if (!($obj instanceof SimpleXMLElement)) {
            throw new XmlException('The input is not instance of SimpleXMLElement, DOMDocument or DOMNode.');
        }
        $result = [];
        $namespaces = array_merge(['' => ''], $obj->getNamespaces(true));
        static::_toArray($obj, $result, '', array_keys($namespaces));

        return $result;
    }
1340746
function parse($html)
		{
			$dom = new \DOMDocument();
			libxml_use_internal_errors(true);
			$dom->loadHTML($html);
			$xpath = new \DOMXPath($dom);
			
			// Load resources for tag actions
			$this->ignoreElements = new ResourceProvider("html_tag_actions/ignore.lst");
			$this->linkElements = new ResourceProvider("html_tag_actions/link.lst");
			$this->bodyElements = new ResourceProvider("html_tag_actions/body.lst");
			$this->inlineElements = new ResourceProvider("html_tag_actions/inline.lst");
			
			/*	
			 *  1st retrieve page title
			 *  With this technique: only process the entire document here 
			 *  as meta is excluded as 'content' and only required for initial title.
			 */

			// Extract title from DOM
			$body = $xpath->query('/')->item(0);
			$titleItem = $xpath->query('//title')->item(0);
			
			if(isset($titleItem))
			{
				$title = $titleItem->textContent;
			}
			$body = $xpath->query('//body')->item(0);
			
			// Try to extract title from OG meta
			foreach ($xpath->query("//meta[@property='og:title']") as $el) 
			{
				$title = $el->getAttribute("content");
			}
			
			$this->recurse($body);
			$Article = new Article();
			if(isset($title))
			{
				$Article->title = $title;
			}
			$Article->textBlocks = $this->textBlocks;
			return $Article;
		}
446349
public function fromXml(SimpleXMLElement $xmlElement)
    {
        $classname = $this->xmlElementToClassname($xmlElement);
        if (!is_null($classname)) {
            $return = new $classname();
            if ($return instanceof ArrayObject) {
                foreach ($xmlElement as $xmlChild) {
                    $return->append($this->fromXml($xmlChild));
                }
            } else {
                $objectData = array();
                foreach ($xmlElement as $xmlChild) {
                    $key = $this->xmlkeyToProperty($xmlChild->getName());
                    if (isset($objectData[$key])) {
                        if (!is_array($objectData[$key])) {
                            $objectData[$key] = array($objectData[$key]);
                        }
                        $objectData[$key][] = $this->fromXml($xmlChild);
                    } else {
                        $objectData[$key] = $this->fromXml($xmlChild);
                    }
                }
                $return->setData($objectData, false);
            }
        } else {
            $return = $this->castValue($xmlElement);
        }

        return $return;
    }
1168606
public static function fromString(string $xml) : DOMDocument
    {
        if (trim($xml) === '') {
            throw InvalidArgumentException::invalidType('non-empty string', $xml);
        }

        $entityLoader = libxml_disable_entity_loader(true);
        $internalErrors = libxml_use_internal_errors(true);
        libxml_clear_errors();

        $domDocument = self::create();
        $options = LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_NONET;
        if (defined('LIBXML_COMPACT')) {
            $options |= LIBXML_COMPACT;
        }

        $loaded = $domDocument->loadXML($xml, $options);

        libxml_use_internal_errors($internalErrors);
        libxml_disable_entity_loader($entityLoader);

        if (!$loaded) {
            $error = libxml_get_last_error();
            libxml_clear_errors();

            throw new UnparseableXmlException($error);
        }

        libxml_clear_errors();

        foreach ($domDocument->childNodes as $child) {
            if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
                throw new RuntimeException(
                    'Dangerous XML detected, DOCTYPE nodes are not allowed in the XML body'
                );
            }
        }

        return $domDocument;
    }
493545
public function render(\DOMDocument $domDocument)
    {
        $scriptXml  = $domDocument->createElement("script");
        $scriptText = $this->__toString();

        $scriptComment = $domDocument->createComment($scriptText);
        $scriptXml->appendChild($scriptComment);

        return $scriptXml;
    }
527960
public function renderStandalone()
    {
        $domDocument                = new \DOMDocument("1.0", "utf-8");
        $domDocument->xmlStandalone = true;

        $domElement = $this->render($domDocument);
        $domDocument->appendChild($domElement);

        return $domDocument;
    }
1067691
public static function ToXmlNode( $nav )
	{
		if ( $nav instanceof \DOMNode ) return $nav;

		if ( $nav instanceof XPathNavigator ) return $nav->getUnderlyingObject();

		return null;
	}
308076
protected function xmlElementToClassname(SimpleXMLElement $xmlElement)
    {
        $xpath = $xmlElement->getName();
        $parent = $xmlElement;
        while ($parent = current($parent->xpath('parent::*'))) {
            $xpath = $parent->getName() . '/' . $xpath;
        }

        foreach ($this->objectMapper as $key => $classname) {
            if (false !== strpos($xpath, $key) && $this->strEndsWith($xpath, $key)) {
                return $classname;
            }
        }
        return null;
    }
1000668
public static function toDOM(BaseElement $element): \DOMDocument
    {
        $doc = new \DOMDocument('1.0', 'utf-8');
        $doc->appendChild($element->toDOM($doc));
        return $doc;
    }
35336
public function process(\DOMDocument $xml)
    {
        $qry = '//tag[@name=\'' . $this->element_name . '\']/@description[. != ""]';

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

        /** @var \DOMElement $node */
        foreach ($nodes as $node) {
            // only transform using markdown if the text contains characters
            // other than word characters, whitespaces and punctuation characters.
            // This is because Markdown is a huge performance hit on the system
            if (!preg_match('/^[\w|\s|\.|,|;|\:|\&|\#]+$/', $node->nodeValue)) {
                $md = \Parsedown::instance();
                $node->nodeValue = $md->parse($node->nodeValue);
            } else {
                // markdown will always surround the element with a paragraph;
                // we do the same here to make it consistent
                $node->nodeValue = '&lt;p&gt;' . $node->nodeValue . '&lt;/p&gt;';
            }
        }

        return $xml;
    }
427190
private function objectToXml($obj, $dom = 0, $item = 0)
    {
        if (!$dom) {
            $dom = new \DOMDocument("1.0");
        }
        if (!$item) {
            $item = $dom->createElement("root");
            $dom->appendChild($item);
        }
        //var_dump($obj);
        foreach ($obj as $key => $val) {
            $itemx = $dom->createElement(is_string($key) ? $key : "item");
            $item->appendChild($itemx);

            if (!is_object($val)) {
                if (is_array($val)) {
                    $val = $this->arrToXml($val, $dom, $itemx);
                } else {
                    $text = $dom->createTextNode($val);
                    $itemx->appendChild($text);
                }
            } else {
                $this->objectToXml($val, $dom, $itemx);
            }
        }
        return $dom->saveXML();
    }
854812
public static function toSimpleXMLElement($xml)
    {
        if ($xml instanceof \SimpleXMLElement) {
            return $xml;
        }

        if ($xml instanceof \DOMDocument) {
            return simplexml_import_dom($xml);
        }

        if (is_string($xml)) {

            if (is_file($xml)) {
                return simplexml_load_file($xml);
            }

            return simplexml_load_string($xml);
        }

        $type = is_object($xml) ? get_class($xml) : gettype($xml);

        throw new \InvalidArgumentException("Cannot convert instance of '$type' to DOMDocument");
    }
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;
    }