@param \DOMNode $node

@return string
333145
protected function htmlFromNode($node)
    {
        $domDocument = new \DOMDocument();
        $newNode = $domDocument->importNode($node, true);
        $domDocument->appendChild($newNode);

        return $domDocument->saveHTML();
    }
1282348
private function getNodeContent(\DOMNode $node)
    {
        $type = $node->attributes->getNamedItem('type');
        if ($type && strtolower($type->nodeValue) == 'xhtml') {
            $result = '';
            foreach ($node->childNodes as $childNode) {
                $result .= $node->ownerDocument->save($childNode);
            }
            return $result;
        } else {
            return $node->nodeValue;
        }
    }
254018
public static function copyChildNodesFromNodeToString(\DOMNode $node)
    {
        $xmlstring = "<rootxml></rootxml>";
        $doc = self::createXmlDocumentFromStr($xmlstring);

        $root = $doc->firstChild;
        $childlist = $node->firstChild->childNodes; // It is necessary because Zend Core For Oracle didn't support
        // access the property Directly.
        foreach ($childlist as $child) {
            $cloned = $doc->importNode($child, true);
            $root->appendChild($cloned);
        }
        $string = $doc->saveXML();
        $string = str_replace('<?xml version="'.self::XML_VERSION.'" encoding="'.self::XML_ENCODING.'"?>', '', $string);
        $string = str_replace('<rootxml>', '', $string);
        $string = str_replace('</rootxml>', '', $string);
        return $string;
    }
1173404
protected function build($node) {
		return preg_replace_callback(
			'/\{~(.+?)~\}|\{\*(.+?)\*\}|\{\-(.+?)\-\}|'.
			'\{\{(.+?)\}\}((\r?\n)*)/s',
			function($expr) {
				if ($expr[1])
					$str='<?php '.$this->token($expr[1]).' ?>';
				elseif ($expr[2])
					return '';
				elseif ($expr[3])
					$str=$expr[3];
				else {
					$str='<?= ('.trim($this->token($expr[4])).')'.
						($this->interpolation?
							(!empty($expr[6])?'."'.$expr[6].'"':''):'').' ?>';
					if (isset($expr[5]))
						$str.=$expr[5];
				}
				return $str;
			},
			$node
		);
	}
610156
private function ensureNodeClass(DOMNode $node)
    {
        $class = $this->nodeClasses['DOMElement'];

        if (true !== ($node instanceof $class) && $node instanceof \DOMElement) {
            return $node->ownerDocument->importNode($node, true);
        }

        return $node;
    }
1187630
private function visitNode(\DOMNode $node)
    {
        if ($this->node !== $node) {
            $this->node->appendChild($node);
        }

        return $node;
    }
162013
public static function get_block_parent_name( \DOMNode $node ) {
		$parent = self::get_block_parent( $node );

		if ( ! empty( $parent ) ) {
			return $parent->tagName;
		} else {
			return '';
		}
	}
331414
public static function getElementsByTagName($node, $tagName)
    {
        $ret = array();
        $nodes = $node->getElementsByTagName($tagName);
        foreach ($nodes as $node) {
            if ($node instanceof DOMElement) {
                array_push($ret, $node);
            }
        }
        return $ret;
    }
357588
static protected function get_cell_list(\DOMNode $node)
    {
        $xpath = new \DOMXpath($node->ownerDocument);

        switch ($node->nodeName) {
            default:
            case "table":
                $query = "tr/td | thead/tr/td | tbody/tr/td | tfoot/tr/td | tr/th | thead/tr/th | tbody/tr/th | tfoot/tr/th";
                break;

            case "tbody":
            case "tfoot":
            case "thead":
                $query = "tr/td | tr/th";
                break;

            case "tr":
                $query = "td | th";
                break;
        }

        return $xpath->query($query, $node);
    }
492380
public static function saveXmlNodeToString(\DOMNode $node)
    {
        $doc = XmlUtil::getOwnerDocument($node);
        $string = $doc->saveXML($node);
        return $string;
    }
709949
protected function normalizeNode(DOMNode $node)
	{
		if (!$node->parentNode)
		{
			// Ignore nodes that have been removed from the document
			return;
		}
		if ($node instanceof DOMElement)
		{
			$this->normalizeElement($node);
		}
		elseif ($node instanceof DOMAttr)
		{
			$this->normalizeAttribute($node);
		}
	}
1237297
protected static function nodeToXpath(\DOMNode $domnode) {
		$dom = new \DOMDocument();
		$dom->formatOutput = true;
		$node = $dom->importNode($domnode, true);
		if($node instanceof \DOMElement)
			$dom->appendChild($node);
		return new \DOMXPath($dom);
	}
122964
protected function &convert(\DOMNode $node)
    {
        $output = array();

        $this->collateNamespaces($node);
        switch ($node->nodeType) {
            case XML_CDATA_SECTION_NODE:
                $output[$this->config['cdataKey']] = trim($node->textContent);
                break;

            case XML_TEXT_NODE:
                $output = trim($node->textContent);
                break;

            case XML_ELEMENT_NODE:

                // for each child node, call the covert function recursively
                for ($i = 0, $m = $node->childNodes->length; $i < $m; $i++) {
                    $child = $node->childNodes->item($i);
                    $v = $this->convert($child);
                    if (isset($child->tagName)) {
                        $t = $child->nodeName;

                        // assume more nodes of same kind are coming
                        if ( ! isset($output[$t])) {
                            $output[$t] = array();
                        }
                        $output[$t][] = $v;
                    } else {
                        //check if it is not an empty text node
                        if ($v !== '') {
                            $output = $v;
                        }
                    }
                }

                if (is_array($output)) {
                    // if only one node of its kind, assign it directly instead if array($value);
                    foreach ($output as $t => $v) {
                        if (is_array($v) && count($v) == 1) {
                            $output[$t] = $v[0];
                        }
                    }
                    if (empty($output)) {
                        //for empty nodes
                        $output = '';
                    }
                }

                // loop through the attributes and collect them
                if ($node->attributes->length) {
                    $a = array();
                    foreach ($node->attributes as $attributeName => $attributeNode) {
                        $attributeName = $attributeNode->nodeName;
                        $a[$attributeName] = (string) $attributeNode->value;
                        $this->collateNamespaces($attributeNode);
                    }
                    // if its an leaf node, store the value in @value instead of directly storing it.
                    if ( ! is_array($output)) {
                        $output = array($this->config['valueKey'] => $output);
                    }
                    $output[$this->config['attributesKey']] = $a;
                }
                break;
        }
        return $output;
    }
966439
protected function lastTagName($node)
    {
        $lastNode = $node->previousSibling;
        while ($lastNode != null) {
            if ($lastNode instanceof DOMElement) {
                break;
            }
            $lastNode = $lastNode->previousSibling;
        }
        $lastTag = '';
        if ($lastNode instanceof DOMElement && $lastNode != null) {
            $lastTag = strtolower($lastNode->nodeName);
        }

        return $lastTag;
    }
509915
public function getMethod(\DOMNode $node)
    {
        $crawler = new Crawler($node);
        $name    = $crawler->attr('name');

        // Initialize
        $method  = new Method($name);

        // Type
        $method->setType(
            preg_match('/(^(get|is)|ToString$)/', $name) ?
            Method::TYPE_ACCESSOR :
            Method::TYPE_ACTION
        );

        // Description
        $descriptions = $crawler->filterXPath('//comment');
        if (count($descriptions) !== 1) {
            throw new \Exception('Only one comment expected');
        }
        $descriptions->rewind();
        $description = $this->getInner($descriptions->current());
        $method->setDescription($description);

        // Parameters
        foreach ($crawler->filterXPath('//parameter') as $node) {
            $method->addParameter($this->getParameter($node));
        }

        // Return
        $returnNodes = $crawler->filterXPath('//return');

        if (count($returnNodes) > 1) {
            throw new \Exception("Should not be more than one return node");
        } elseif (count($returnNodes) == 1) {
            $returnNodes->rewind();
            list($type, $description) = $this->getReturn($returnNodes->current());

            $method->setReturnType($type);
            $method->setReturnDescription($description);
        }

        return $method;
    }
739564
public static function get_ancestors( \DOMNode $node ) {
		$result = [];

		while ( ( $node = $node->parentNode ) && ( $node instanceof \DOMElement ) ) { // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
			$result[] = $node;
		}

		return $result;
	}
796046
public static function to_string( \DOMDocument $dom ) {
		$html5 = new HTML5();
		preg_match( '/<body>(.*)<\/body>/s', $html5->saveHTML( $dom ), $match );

		return $match[1];
	}