Gets elements by tagname.

This function returns all subnodes that have a given tagname.

@param DOMElement $node    DOMElement object
@param string     $tagName Tag name

@return array of DOMElement objects
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;
    }
988334
public static function getChildElements(DOMElement $parent, $childName)
    {
        $listElements = $parent->getElementsByTagName($childName);
        if ($listElements->length > 0) {
            $list = [];

            for ($i = 0; $i < $listElements->length; $i++) {
                $currentItem = $listElements->item($i);

                if (!$parent->isSameNode($currentItem->parentNode)) {
                    continue;
                }

                $list[] = $currentItem;
            }

            return $list;
        }

        return [];
    }
1196167
protected static function getPreviousElement(\DOMNode $node)
    {
        while ($node && ($node = $node->previousSibling)) {
            if ($node instanceof \DOMElement) {
                break;
            }
        }

        return $node;
    }
154379
private function _getNodeAttributes(DOMElement $pNode)
    {
        $attributes = array();
        if ($pNode->attributes->length) {
            foreach ($pNode->attributes as $key => $attr) {
                $attributes[$key] = $attr->value;
            }
        }

        return $attributes;
    }
917636
public static function xmlStrToArray($xmlString, $tagName = false, $elementCount = false)
    {
        $doc = new DOMDocument();
        try {
            $doc->loadXML($xmlString);
        } catch (Exception $exc) {
            return [];
        }
        $result = [];

        if (is_string($tagName)) {
            $nodes = $doc->documentElement->getElementsByTagName($tagName);
            if (false == $elementCount) {
                $elementCount = $nodes->length;
            }
            for ($i = 0; $i < $elementCount; $i++) {
                $result[] = self::domNodeToArray($nodes->item($i));
            }
        } else {
            $result = self::domNodeToArray($doc->documentElement);
        }

        return $result;
    }
1110500
protected function getAttributes(DOMElement $element)
	{
		$attributes = array();
		foreach ($element->attributes as $attribute)
		{
			$key = $attribute->namespaceURI . '#' . $attribute->nodeName;
			$attributes[$key] = $attribute->nodeValue;
		}

		return $attributes;
	}
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;
    }
409300
protected function getBlock(\DOMElement $element) {
    $block = '';
    /** @var \DOMNode $node */
    foreach ($element->childNodes as $node) {
      switch ($node->nodeType) {

        case XML_ELEMENT_NODE:
          /** @var \DOMElement $node */
          switch ($node->nodeName) {

            // Explicitly handle these elements.

            case 'i':
            case 'em':
              $block .= '*' . $this->getBlock($node) . '*';
              break;

            case 'b':
            case 'strong':
              $block .= '**' . $this->getBlock($node) . '**';
              break;

            case 'a':
              if ($node->hasAttribute('href')) {
                $block .= '[' . $this->getBlock($node) . ']' .
                  '(' . $node->getAttribute('href') . ')';
              }
              break;

            // Other inline elements.
            default:
              // Recursively handle any descendant elements we care about.
              $block .= $this->getBlock($node);
              break;

          }
          break;

        case XML_TEXT_NODE:
          /** @var \DOMText $node */
          $block .= self::escape($node->textContent);
          break;

      }
    }

    // Handle white-listed elements.
    if (in_array($element->nodeName, $this->white_list)) {
      $tag = $element->cloneNode();
      if (!empty($block)) {
        $tag->appendChild(new \DOMText($block));
      }
      $block = $this->dom->saveXML($tag);
    }

    return $block;
  }
312050
public function filter($node, $tagname)
    {
        $ret = array();
        while ($node = Dom::getNextSiblingElement($node)) {
            array_push($ret, $node);
        }
        return $ret;
    }
681214
public static function getLinks(\DOMDocument $html, $tagName = 'link')
    {
        $links = [];

        foreach ($html->getElementsByTagName($tagName) as $link) {
            if ($link->hasAttribute('rel') && $link->hasAttribute('href')) {
                $rel = trim(strtolower($link->getAttribute('rel')));
                $href = $link->getAttribute('href');

                $links[] = [$rel, $href, $link];
            }
        }

        return $links;
    }
739095
public function createNode($tagName, $entityName = null)
    {
        if ($tagName instanceof Element) {
            $this->push($tagName);
        } else {
            $this->push(new Element($tagName, $entityName));
        }

        return $this->last();
    }
1197428
protected static Element getChildElement(final Element parent, final String tagName) {
        List<Element> elements = getElements(parent, tagName);
        if (elements.size() > 0) {
            return elements.get(0);
        } else {
            return null;
        }
    }
1230089
protected function getNodeValueByTagNameNS(DOMElement $node, $namespace, $tagName)
    {
        $results = $node->getElementsByTagNameNS($namespace, $tagName);
        for ($i = 0; $i < $results->length; $i++) {
            $result = $results->item($i);
            if (is_null($result->nodeValue)) {
                continue;
            }

            return $result->nodeValue;
        }

        return false;
    }
1005676
public static function getFirstElementByTagName($node, $subnode_name)
    {
        $nodes = $node->getElementsByTagName($subnode_name);
        if ($nodes->length > 0)
        {
            return $nodes->item(0);
        }
        else
        {
            return null;
        }
    }
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;
	}
977520
def getElementsByTagName(self, tagName):
        '''
            
        '''
        ret = TagCollection()
        if len(self) == 0:
            return ret

        tagName = tagName.lower()
        _cmpFunc = lambda tag : bool(tag.tagName == tagName)
        
        for tag in self:
            TagCollection._subset(ret, _cmpFunc, tag)

        return ret
6105
protected function getTagObject($tagName)
    {
        if (!$this->extensionsLoaded) {
            $this->loadExtensions();
        }

        if (!array_key_exists($tagName, $this->tagObjects)) {
            return null;
        }

        $tagObject = $this->tagObjects[$tagName];
        $tagObject->setParsingCssObject($this->parsingCss);
        $tagObject->setCssConverterObject($this->cssConverter);
        $tagObject->setPdfObject($this->pdf);
        if (!is_null($this->debug)) {
            $tagObject->setDebugObject($this->debug);
        }

        return $tagObject;
    }