@param string|\DOMNode $mixed

@return array|null
432370
public function asArray($mixed): ?array
    {
        $data = $this->_simpleXml($mixed);
        return $data ? $this->_asArray($data) : null;
    }
778967
public function parse($html)
    {
        $errorHandling = libxml_use_internal_errors(true);

        $dom = new \DOMDocument();
        $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);

        $xpath = new \DOMXpath($dom);

        foreach ($this->componentFactories as $tag => $factory) {
            $tags = $xpath->query('//' . $tag);

            if ($tags) {
                foreach ($tags as $node) {
                    $factory->parse($node);
                }
            }
        }

        libxml_clear_errors();
        libxml_use_internal_errors($errorHandling);

        return $dom->saveHTML();
    }
786486
private function loadTypes(&$tags, \DOMXPath $xpath, \DOMNode $context = null)
    {
        $result = [];

        /** @var \DOMElement $node */
        foreach ($xpath->query('x:types/x:type', $context) as $node) {
            $value = $this->loadType($xpath, $node, $tags);
            $result[$value['name']] = $value;
        }

        return $result;
    }
713656
public function find_parent_by_tag($tag)
	{
		$node = $this->parent();

		while($this->parent() != null
			&& !$node instanceof Node_Container_Document)
		{
			if($node->tag() === $tag)
				return $node;

			$node = $node->parent();
		}

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

        return $node;
    }
39892
public function getNodes($path)
    {
        $domXPath = new \DOMXpath($this->domDocument);
        // TODO: Swap the lines below for version 5.1.
        //			$nodes = $domXPath->evaluate($path);
        $nodes = $domXPath->query($path);
        if ($nodes) {
            return ($nodes->length > 0) ? $nodes : null;
        } else {
            throw new Exception('Bad XPath expression: ' . $path);
        }
    }
43916
protected function getValue(DOMNode $node)
    {
      // Init value
      $value = null;

      if(is_numeric($node->nodeValue))
        $value = $node->nodeValue;
      elseif(is_string($node->nodeValue))
        $value = utf8_decode($node->nodeValue);

      return $value;
    }
239837
public function processNode(Node $node, Scope $scope): array
    {
        if ('__construct' !== $node->name->toLowerString()) {
            return [];
        }

        if (0 === \count($node->params)) {
            return [];
        }

        $params = \array_filter($node->params, static function (Node\Param $node): bool {
            return null !== $node->default;
        });

        if (0 === \count($params)) {
            return [];
        }

        /** @var Reflection\ClassReflection $classReflection */
        $classReflection = $scope->getClassReflection();

        if ($classReflection->isAnonymous()) {
            return \array_map(static function (Node\Param $node): string {
                /** @var Node\Expr\Variable $variable */
                $variable = $node->var;

                /** @var string $parameterName */
                $parameterName = $variable->name;

                return \sprintf(
                    'Constructor in anonymous class has parameter $%s with default value.',
                    $parameterName
                );
            }, $params);
        }

        $className = $classReflection->getName();

        return \array_map(static function (Node\Param $node) use ($className): string {
            /** @var Node\Expr\Variable $variable */
            $variable = $node->var;

            /** @var string $parameterName */
            $parameterName = $variable->name;

            return \sprintf(
                'Constructor in %s has parameter $%s with default value.',
                $className,
                $parameterName
            );
        }, $params);
    }
1001315
public static function Html($Mixed) {
      if (!is_string($Mixed)) {
         return self::To($Mixed, 'Html');
      } else {
         $IsHtml = strpos($Mixed, '<') !== FALSE
            || (bool)preg_match('/&#?[a-z0-9]{1,10};/i', $Mixed);

         if ($IsHtml) {
            // The text contains html and must be purified.

            $Formatter = Gdn::Factory('HtmlFormatter');
            if(is_null($Formatter)) {
               // If there is no HtmlFormatter then make sure that script injections won't work.
               return self::Display($Mixed);
            }

            // Allow the code tag to keep all enclosed html encoded.
            $Mixed = preg_replace(
               array('/<code([^>]*)>(.+?)<\/code>/sei'),
               array('\'<code\'.RemoveQuoteSlashes(\'\1\').\'>\'.htmlspecialchars(RemoveQuoteSlashes(\'\2\')).\'</code>\''),
               $Mixed
            );
            
            // Do HTML filtering before our special changes
            $Mixed = $Formatter->Format($Mixed);

            // Links
            $Mixed = Gdn_Format::Links($Mixed);
            // Mentions & Hashes
            $Mixed = Gdn_Format::Mentions($Mixed);

            // nl2br
            if(C('Garden.Format.ReplaceNewlines', TRUE)) {
               $Mixed = preg_replace("/(\015\012)|(\015)|(\012)/", "<br />", $Mixed);
               $Mixed = FixNl2Br($Mixed);
            }
            
            $Result = $Mixed;            

//            $Result = $Result.
//               "<h3>Html</h3><pre>".nl2br(htmlspecialchars(str_replace("<br />", "\n", $Mixed)))."</pre>".
//               "<h3>Formatted</h3><pre>".nl2br(htmlspecialchars(str_replace("<br />", "\n", $Result)))."</pre>";
         } else {
            // The text does not contain html and does not have to be purified.
            // This is an optimization because purifying is very slow and memory intense.
            $Result = htmlspecialchars($Mixed, ENT_NOQUOTES, 'UTF-8');
            $Result = Gdn_Format::Mentions($Result);
            $Result = Gdn_Format::Links($Result);
            if(C('Garden.Format.ReplaceNewlines', TRUE)) {
               $Result = preg_replace("/(\015\012)|(\015)|(\012)/", "<br />", $Result);
               $Result = FixNl2Br($Result);
            }
         }
         
         return $Result;
      }
   }
1001263
private function parseNodeData(\DOMNode $node, $path)
    {
        $nodeData = [];

        foreach ($node->childNodes as $childNode) {
            $childrenData = $this->convertNode($childNode, ($path ? $path . '/' : '') . $childNode->nodeName);
            if ($childrenData === null) {
                continue;
            }
            $nodeData = $this->mergeChildData($nodeData, $childrenData);
        }

        if (is_array($nodeData) && empty($nodeData)) {
            $nodeData = null;
        }

        return $nodeData;
    }
1362354
public function siblings($css = null)
    {
        $query = $this->_document->getQuery();

        $nodes = [];
        foreach ($this->_nodes as $node) {
            $cur_xpath = $node->getNodePath();
            foreach ($query->css('parent::' . ($css ?: '*'), $node) as $node2) {
                /**
                 * @var \DOMNode $node2
                 */
                /** @noinspection SlowArrayOperationsInLoopInspection */
                if ($node2->getNodePath() !== $cur_xpath) {
                    $nodes[$node2->getNodePath()] = $node2;
                }
            }
        }

        return new SelectorList($this, array_values($nodes));
    }
1356880
private function decodeObjectNode(\DOMNode $node): array
    {
        $data = [];
        foreach ($node->childNodes as $childNode) {
            if ($childNode instanceof \DOMText) {
                continue;
            }

            $data[$childNode->getAttribute('name')] = $this->decodeNode($childNode);
        }

        return $data;
    }
1268919
protected function valueOf(DOMNode $node)
	{
		switch ($node->nodeName)
		{
			case 'input':

				switch ($node->getAttribute('type'))
				{
					case 'checkbox':
						return $node->getAttribute('checked') ? $node->getAttribute('value') : false;
						break;

					default:
						return $node->getAttribute('value');
				}

			break;
		}
		return null;
	}
1369696
public function getNode($ref): ?Node
    {
        $nodeRef = $this->toNodeRef($ref);
        if (!$nodeRef instanceof NodeRef) {
            return null;
        }

        try {
            return $this->ncrCache->getNode($nodeRef);
        } catch (NodeNotFound $e) {
            return null;
        } catch (\Throwable $e) {
            if ($this->debug) {
                throw $e;
            }

            $this->logger->error(
                sprintf(
                    '%s::Unable to process twig "ncr_get_node" function for [{node_ref}].',
                    ClassUtils::getShortName($e)
                ),
                ['exception' => $e, 'node_ref' => (string)$nodeRef]
            );
        }

        return null;
    }
433516
public function parse($mixed)
    {
        if (\Staq\Util::isStack($mixed)) {
            return $this->parseFromStack($mixed);
        }
        return $this->parseFromString($mixed);
    }
1269091
function cast($obj=NULL) {
		if (!$obj)
			$obj=$this;
		return $obj->document+['_id'=>$this->id];
	}
470911
protected function xpath($query, DOMNode $node = null)
	{
		$query = str_replace('$XSL', '"' . self::XMLNS_XSL . '"', $query);

		return iterator_to_array($this->xpath->query($query, $node));
	}