Getter for retrieving xpath from a DOMElement

@param \DOMElement $nodeList
@param integer $level
@return type
4792
public function getPaths(\DOMElement $nodeList, $level = 0)
    {
        $output = $nodeList->getNodePath();

        foreach ($nodeList->childNodes as $childObject) {
            $output .= $childObject->getNodePath() . "\n";

            if ($childObject instanceof \DOMElement) {
                $output .= $this->getElement($childObject, $level + 1, true);
            }
        }
        return $output;
    }
186633
protected function getDatabaseFromDatabaseElement(\DOMElement $databaseElement)
    {
        $database = $databaseElement->getAttribute('name');
        if (empty($database)) {
            throw new \LogicException('Unnamed database node.');
        }

        return $database;
    }
310872
public function find(string $selector, string $prefix = 'descendant::'): NodeList {
        $converter = new CssSelectorConverter();

        return $this->findXPath($converter->toXPath($selector, $prefix));
    }
1323389
protected function createTree(&$list, $parent, $level = 1)
    {
        $tree = [];
        foreach ($parent as $l) {
            $l->level = $level;
            if (isset($list[$l->id])) {
                $l->children = $this->createTree($list, $list[$l->id], ++$level);
                $level--;
            }
            $tree[] = $l;
        }

        return $tree;
    }
726970
private function getEqualNodes(DOMElement $node, $prefix = null)
    {
        $name = $this->prefixKey($node->nodeName, $prefix);

        return $node->xpath(
            sprintf(".|following-sibling::*[name() = '%s']|preceding-sibling::*[name() = '%s']", $name, $name)
        );
    }
305798
public static function getLevelByName($level)
    {
        $level = strtoupper($level);
        if (!isset(static::$levelNameToLevel[$level])) {
            return static::ALL;
        }

        return static::$levelNameToLevel[$level];
    }
144559
public function getMenu($level = 1)
    {
        if (class_exists(ContentController::class)) {
            $controller = Injector::inst()->get(ContentController::class);
            return $controller->getMenu($level);
        }
    }
321024
public static function getNextSiblingOfType(\DOMElement $element, $elementType) {
    $nextSibling = $element->nextSibling;
    while ($nextSibling && $nextSibling->nodeType != $elementType) {
      $nextSibling = $nextSibling->nextSibling;
    }
    return $nextSibling;
  }
486457
static function fetchNodePathString( $nodeList )
    {
        $pathList = array();
        foreach ( $nodeList as $node )
        {
            $pathList[] = $node->attribute( 'path_string' );
        }
        return $pathList;
    }
1371749
public function findByLevels($levels = 1, $ids = array())
    {
        $query = $this->createQueryBuilder('c');

        if ($levels > 0) {
            $selects = ['c'];
            for ($i = 1; $i <= $levels; ++$i) {
                $selects[] = 'c'.$i;
            }

            $query->select($selects);

            for ($i = 1; $i <= $levels; ++$i) {
                $previous = ($i - 1 == 0) ? '' : ($i - 1);
                $query->leftJoin('c'.$previous.'.children', 'c'.$i, 'WITH', 'c'.$i.'.active = :active AND c'.$i.'.showInNavigation = :show');
            }
        }

        if ($ids) {
            $query->andWhere('c.id IN (:ids)')->setParameter('ids', $ids);
        } else {
            $query->andWhere('c.parent IS NULL');
        }

        $query->andWhere('c.active = :active')->setParameter('active', true);
        $query->andWhere('c.layout = :layout')->setParameter('layout', false);
        $query->andWhere('c.showInNavigation = :show')->setParameter('show', true);

        return $query->getQuery()->getResult();
    }
1143760
public function extract(ElementVersion $elementVersion, ElementStructure $elementStructure = null, $language)
    {
        $elementtype = $this->elementSourceManager->findElementtype($elementVersion->getElement()->getElementtypeId());

        if (!$elementtype) {
            throw new \LogicException('No elementtype found.');
        }

        $titles = [];

        if ($elementStructure) {
            $mappings = $elementtype->getMappings();

            if ($mappings) {
                foreach ($mappings as $key => $mapping) {
                    if ($mapper = $this->findFieldMapper($key)) {
                        $title = $mapper->map($elementStructure, $language, $mapping);
                        if ($title) {
                            $titles[$key] = $title;
                        }
                    }
                }
            }
        }

        if (empty($titles['backend'])) {
            $titles['backend'] = '['.$elementtype->getTitle().', '.$language.']';
        }

        return $titles;
    }
439417
public static function getChildElement(DOMElement $parent, $childName)
    {
        $listElements = $parent->getElementsByTagName($childName);
        if ($listElements->length > 0) {
            for ($i = 0; $i < $listElements->length; $i++) {
                $currentItem = $listElements->item($i);
                if ($parent->isSameNode($currentItem->parentNode)) {
                    return $currentItem;
                }
            }
        }

        return null;
    }
406451
private function getNode($list, $doc)
	{
		foreach($list as $item)
		{
			$result = XmlUtil::selectSingleNode($doc->documentElement, $item);

			if ($result != null)
			{
				return $result;
			}
		}
		return null;
	}
699364
public static function nodesTreeList($parentId = 0, $level = 0, $shiftPrefix = '. ')
    {
        if (!isset(static::$_nodesTreeList[$parentId][$level][$shiftPrefix])) {
            $tree = [];
            $list = [];

            $parentNode = static::node($parentId);
            if (!empty($parentNode)) {
                $grandParentId = $parentNode['parent_id'];
                $grandParentNode = static::node($grandParentId);
                $nodePath = (empty($grandParentNode->nodePath)
                             ? '' : $grandParentNode->nodePath . '/'
                         ) . $parentNode['slug'];
                $list[$parentId] = str_repeat($shiftPrefix, $level) . $nodePath;
                $tree[$parentId] = str_repeat($shiftPrefix, $level) . $parentNode['slug'];
                static::saveNodePath($parentId, $nodePath);
            }

            $children = static::nodeChildren($parentId);
            foreach ($children as $child) {
                static::$_nodes[$child['id']] = $child;
                $list += static::nodesTreeList($child->id, $level+1, $shiftPrefix);
                $tree += static::nodesTree($child->id, $level+1, $shiftPrefix);
            }
            static::$_nodesTree[$parentId][$level][$shiftPrefix] = $tree;
            static::$_nodesTreeList[$parentId][$level][$shiftPrefix] = $list;
        }    
        return static::$_nodesTreeList[$parentId][$level][$shiftPrefix];
    }
176452
protected function fromElementOrderNodeIteratorParts( $baseIter )
	{
		$isNode = null;
		$this->itemSet = array();
		while ( $baseIter->MoveNext() )
		{
			// BMS 2018-01-08 Changed to be more careful about when getIsNode() is called
			//                Same change must be made to DocumentOrderNodeIterator
			$current = $baseIter->getCurrent();

			if ( is_null( $isNode ) )
			{
				$isNode = $current instanceof XPathNavigator && $current->getIsNode();
			}
			else
			{
				if ( ( ! $isNode && $current instanceof XPathNavigator ) || ( $isNode && $current->getIsNode() != $isNode ) )
				{
					throw XPath2Exception::withErrorCodeAndParam( "XPTY0018", Resources::XPTY0018, $baseIter->getCurrent()->getValue() );
				}
			}

			/**
			 * @var DOMXPathItem $clone
			 */
			$clone = CoreFuncs::CloneInstance( $baseIter->getCurrent() );
			$localName = $clone->getLocalName();

			$this->itemSet[ $localName ][] = $clone;
		}

		if ( ! is_null( $isNode ) && $isNode )
		{
			if ( count( $this->itemSet ) > 1 )
			{
				ksort( $this->itemSet );
			}

			foreach ( $this->itemSet as $elementName => $element )
			{
				if ( count( $element ) < 2 ) continue;

				$comparer = new XPathComparer();
				$result = usort( $this->itemSet[ $elementName ], function( $a, $b )
				{
					return strcasecmp( $a->getValue(), $b->getValue() );
				} );
			}

		}
	}
139613
protected function loadElementsFromXmlFileWithPath($xmlFile, $nodePath)
    {
        $xml = file_get_contents($xmlFile);
        // Remove whitespaces between closing tag and opening tag.
        $xml = preg_replace('/>\s+</', '><', $xml);

        $doc = new \DOMDocument();
        $doc->loadXML($xml);

        $xpath = new \DOMXpath($doc);
        $elements = $xpath->query($nodePath);

        return $elements;
    }
711234
public function getNode($nodeId)
    {
        static $instance = array();
        if (isset($instance[$nodeId]))
            return $instance[$nodeId];
        $nodes = $this->nodeSet;
        if (empty($nodes))
            return NULL;
        foreach ($nodes as $node):
            if ($node->getId() == $nodeId):
                $instance[$nodeId] = &$node;
                break;
            endif;
        endforeach;
        return NULL;
    }