# Returns a DOMNode.
777736
protected static function renderNode($node, $document)
    {
        if (static::isTag($node)) {
            # Strip the leading "#"
            $tagName    = substr(array_shift($node), 1);
            $attributes = array();

            if (sizeof($node) > 2) {
                throw new \UnexpectedValueException(
                    "Tags must not consist of more than three elements"
                );
            }

            foreach ($node as $argv) {
                # Is the argument an associative array of attributes?
                if (is_array($argv) and count(array_filter(array_keys($argv), "is_string")) > 0) {
                    $attributes = $argv;
                } else {
                    $content = $argv;
                }
            }

            $el = $document->createElement($tagName);

            foreach ($attributes as $attr => $value) {
                if (is_array($value)) $value = join(" ", $value);

                $el->setAttribute($attr, (string) $value);
            }

            if (isset($content)) {
                $el->appendChild(static::renderNode($content, $document));
            }
        } else if (is_array($node)) {
            $el = $document->createDocumentFragment();

            foreach ($node as $child) {
                $el->appendChild(static::renderNode($child, $document));
            }
        } else {
            $node = (string) $node;
            if (!empty($node)) $node .= "\n";
            $el = $document->createTextNode($node);
        }

        return $el;
    }
1220385
protected static function getNodes(DOMDocument $dom, $type)
	{
		$nodes  = [];
		$prefix = ($type === 'attribute') ? '@' : '';
		$xpath  = new DOMXPath($dom);

		// Get natural nodes
		foreach ($xpath->query('//' . $prefix . '*') as $node)
		{
			$nodes[] = [$node, $node->nodeName];
		}

		// Get XSL-generated nodes
		foreach ($xpath->query('//xsl:' . $type) as $node)
		{
			$nodes[] = [$node, $node->getAttribute('name')];
		}

		// Get xsl:copy-of nodes
		foreach ($xpath->query('//xsl:copy-of') as $node)
		{
			if (preg_match('/^' . $prefix . '(\\w+)$/', $node->getAttribute('select'), $m))
			{
				$nodes[] = [$node, $m[1]];
			}
		}

		return $nodes;
	}
116902
def node(self, parent=None, tag='g', attrib=None, **extras):
        """"""
        if parent is None:
            parent = self.root
        attrib = attrib or {}
        attrib.update(extras)

        def in_attrib_and_number(key):
            return key in attrib and isinstance(attrib[key], Number)

        for pos, dim in (('x', 'width'), ('y', 'height')):
            if in_attrib_and_number(dim) and attrib[dim] < 0:
                attrib[dim] = -attrib[dim]
                if in_attrib_and_number(pos):
                    attrib[pos] = attrib[pos] - attrib[dim]

        for key, value in dict(attrib).items():
            if value is None:
                del attrib[key]

            attrib[key] = to_str(value)
            if key.endswith('_'):
                attrib[key.rstrip('_')] = attrib[key]
                del attrib[key]
            elif key == 'href':
                attrib[etree.QName('http://www.w3.org/1999/xlink',
                                   key)] = attrib[key]
                del attrib[key]
        return etree.SubElement(parent, tag, attrib)
314122
public function toXML( DOMDocument $dom )
    {
        $zoneNode = $dom->createElement( 'zone' );
        foreach ( $this->attributes as $attrName => $attrValue )
        {
            switch ( $attrName )
            {
                case 'id':
                    $zoneNode->setAttribute( 'id', 'id_' . $attrValue );
                    break;

                case 'action':
                    $zoneNode->setAttribute( 'action', $attrValue );
                    break;

                case 'blocks':
                    foreach ( $this->attributes['blocks'] as $block )
                    {
                        $blockNode = $block->toXML( $dom );
                        $zoneNode->appendChild( $blockNode );
                    }
                    break;

                default:
                    $node = $dom->createElement( $attrName );
                    $nodeValue = $dom->createTextNode( $attrValue );
                    $node->appendChild( $nodeValue );
                    $zoneNode->appendChild( $node );
                    break;
            }
        }

        return $zoneNode;
    }
1205083
protected function getInner(\DOMNode $node)
    {
        $c14n = $node->C14N();
        $begin = strpos($c14n, '>');
        $end   = strrpos($c14n, '<');

        $content = substr($c14n, $begin + 1, $end - $begin - 1);

        return $content;
    }
177375
public function getNode()
    {
        if (!$this->node) {
            throw new \RuntimeException(sprintf(
                'Trying to retrieve node when no node has been set. An event ' .
                'listener should have set the node when persisting document "%s"',
                DocumentHelper::getDebugTitle($this->document)
            ));
        }

        return $this->node;
    }
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;
    }
640936
public function getNodeType()
	{
		if ( is_null( $this->domNode ) ) return null;
		return isset(  DOMXPathNavigator::$nodeTypeMap[ $this->domNode->nodeType ] )
			? DOMXPathNavigator::$nodeTypeMap[ $this->domNode->nodeType ]
			: XPathNodeType::Element;
	}
504915
public function html() {
    if (($el = $this->getElement()) === NULL) return NULL;
    
    return implode('',xml::export($el->childNodes));
  }
985559
public function parent() {
		$parent = $this->domnode;
		if(!$parent)
			return new Node(null);
		while(true) {
			$parent = $parent->parentNode;
			if(!$parent)
				return;
			if($parent->nodeType == XML_ELEMENT_NODE)
				return new Node($parent);
		}
	}
760014
def dom(self):
        """"""
        try:
            dom = self._original_document.dom
            # cleaning doesn't return, just wipes in place
            html_cleaner(dom)
            return leaf_div_elements_into_paragraphs(dom)
        except ValueError:
            return None
470030
def get_dom(self) -> str:
        

        if self.is_running:
            return self.dumps()

        if self.dom is not None:
            return self.dom

        dom = self.dumps()
        self.dom = dom
        return dom
1058797
public function getNode()
    {
        if(null === $this->node)
        {
            $request = $this->requestStack->getCurrentRequest();
            $this->node = $this->readNode(RequestFilter::getFinder($request, $this->contentPath));
        }

        return $this->node;
    }
11564
public function getParentNode()
    {
        if (!$this->parentNode) {
            throw new \RuntimeException(sprintf(
                'Trying to retrieve parent node when no parent node has been set. An event ' .
                'listener should have set the node when persisting document "%s"',
                DocumentHelper::getDebugTitle($this->document)
            ));
        }

        return $this->parentNode;
    }
923570
public function getDomDocumentResponse()
    {
        $response = $this->getResponse();
        $xml = new DOMDocument();
        $xml->loadXML($response);
        return $xml;
    }
1278638
final public function parent()
    {
        $parent = NULL;

        if(!!isset($this->dom_element->parentNode))
        {
            if($this->dom_element->parentNode->nodeType == 1)
            {
                $parent = new PHPHtmlDomElement($this->dom_element->parentNode);
            }
            else
            {
                $parent = $this->dom_element->parentNode;
            }
        }
        return $parent;
    }
1279034
public function getMiddleNode(): ?IUnaryNode {
        $head = $this->getHead();

        if (null === $head) return null;

        $p = $head;
        $q = $head;

        while (null !== $p &&
            null !== $q && //actually not really necessary since $p and $q point to the same object
            null !== $q->getNext()
        ) {
            $p = $p->getNext();
            $q = $q->getNext()->getNext();
        }
        return $p;
    }