@param \DOMNodeList $elements

@return TreeNodeInterface[]
337807
private function mapNodes(\DOMNodeList $elements)
    {
        $nodes = [];

        foreach ($elements as $element) {
            $node = $this->mapNode($element);
            $nodes[$node->getId()] = $node;
        }

        return $nodes;
    }
363703
protected function _toArray(DOMNodeList $nodes) {
		$array = array();
		foreach ($nodes as $node) {
			if ($node->nodeType != XML_ELEMENT_NODE) {
				continue;
			}
			if ($node->hasAttributes()) { // deep
				if ($node->tagName == 'error') {
					$array = array(
						'id' => $node->getAttribute('id'),
						'code' => $node->getAttribute('code'),
						'auxCode' => $node->getAttribute('auxCode'),
						'message' => $node->nodeValue
					);
				} else {
					// in the case of custom charges, use the id for the key
					if ($node->hasAttribute('code') && $node->getAttribute('code')) {
						$key = $node->getAttribute('code');

						$tmpArr = array();

						if ($node->hasAttribute('id')) {
							$tmpArr = array(
								'id' => $node->getAttribute('id')
							);
						}
						$tmpArr = $tmpArr + array('code'=>$key);

						// charges need to be a nested array since there can be multiple charges with the same charge code
						if ($node->tagName == 'charge') {
							$array[$key][] = $tmpArr;
						} else {
							$array[$key] = $tmpArr;
						}

						unset($tmpArr);

					} else {
						$key = $node->getAttribute('id');
						$array[$key] = array('id' => $node->getAttribute('id'));
					}
					$array[$key] = $array[$key] + $this->_toArray($node->childNodes);
				}
			} else {
				if ($node->tagName == 'errors') {
					$array[$node->tagName][] = $this->_toArray($node->childNodes);
				} else if ($node->childNodes->length > 1) { // sub array
					$array[$node->tagName] = $this->_toArray($node->childNodes);
				} else {
					$array[$node->tagName] = $node->nodeValue;
				}
			}
		}
		return $array;
	}
385766
public function newNodeList(iterable $nodes = null): NodeList {

        if (!is_iterable($nodes)) {
            if (!is_null($nodes)) {
                $nodes = [$nodes];
            } else {
                $nodes = [];
            }
        }

        return new NodeList($this->document(), $nodes);
    }
1232152
protected function getValidatorsForFields(array $elements = [])
    {
        $return = [];
        foreach ($this->validators as $key => $validator) {
            if (!empty($elements) && !array_intersect($elements, $validator->getElements())) {
                continue;
            }
            $return[$key] = $validator;
        }
        $rules = $this->getRules();
        foreach ($rules as $key => $rule) {
            if (isset($return[$key]) || !empty($elements) && !array_intersect($elements, $rule[0])) {
                continue;
            }
            $return[$key] = $this->getValidator($key);
        }

        return array_values($return);
    }
798209
protected function generateTree(Collection $collection, Collection $children)
    {
        $children->map(function (AdminMenuInterface $menuItem) use ($collection, &$tree) {
            $tree[] = [
                'routeName' => $menuItem->getRouteName(),
                'cssClass'  => $menuItem->getCssClass(),
                'name'      => $menuItem->getName(),
                'children'  => $this->generateTree($collection, $this->filterElements($collection, $menuItem))
            ];
        });
        
        return $tree;
    }
916801
protected function getItems( \DomNodeList $nodes )
	{
		$codes = $map = [];
		$manager = \Aimeos\MShop::create( $this->getContext(), 'product' );

		foreach( $nodes as $node )
		{
			if( $node->nodeName === 'productitem' && ( $attr = $node->attributes->getNamedItem( 'ref' ) ) !== null ) {
				$codes[$attr->nodeValue] = null;
			}
		}

		$search = $manager->createSearch()->setSlice( 0, count( $codes ) );
		$search->setConditions( $search->compare( '==', 'product.code', array_keys( $codes ) ) );

		foreach( $manager->searchItems( $search, [] ) as $item ) {
			$map[$item->getCode()] = $item;
		}

		return $map;
	}
1248604
public function children($selector=null)
    {
        $result = $this->createChildInstance();

        if (isset($this->document) && $this->length > 0) {
            if (isset($this->root_instance) || $this->getXpathQuery()) {
                foreach ($this->nodes as $node) {
                    if ($node->hasChildNodes()) {
                        $result->loadDomNodeList($node->childNodes);
                    }
                }
            } else {
                $result->loadDomNodeList($this->document->childNodes);
            }

            if ($selector !== false) { // filter out text nodes
                $filtered_elements = array();
                foreach ($result->getElements() as $result_elm) {
                    $filtered_elements[] = $result_elm;
                }
                $result->nodes = $filtered_elements;
                $result->length = \count($result->nodes);
            }

            if ($selector) {
                $result = $result->filter($selector);
            }
        }

        return $result;
    }
194232
protected function registerNodes($nodeList)
    {
        // If the node list is invalid
        if (!is_array($nodeList) && !($nodeList instanceof \DOMNodeList)) {
            throw new RuntimeException(RuntimeException::INVALID_NODE_LIST_STR, RuntimeException::INVALID_NODE_LIST);
        }

        $nodes = [];

        // Run through and register all nodes
        /** @var \DOMNode $node */
        foreach ($nodeList as $node) {
            $nodes[$node->getNodePath()] = $this->registerNode($node);
        }

        return $nodes;
    }
994537
private function parseAggregationsProviders(\DOMXPath $xpath, \DOMNode $rootNode)
    {
        $providers = [];

        foreach ($xpath->query(self::AGGREGATIONS_PROVIDERS_PATH, $rootNode) as $providerNode) {
            $providers[$providerNode->getAttribute('name')] = $providerNode->nodeValue;
        }

        return $providers;
    }
697979
private function getNodeList() : Generator
    {
        $xpath    = new DOMXPath($this->document);
        $nodeList = $xpath->query('//input | //textarea | //select | //div[@data-input-name]');

        /** @var DOMElement $node */
        foreach ($nodeList as $node) {
            $name = $node->getAttribute('name');
            if (! $name) {
                $name = $node->getAttribute('data-input-name');
            }

            if (! $name || $node->getAttribute('type') === 'submit') {
                // At least a name is needed to submit a value.
                // Silently continue, might be a submit button.
                continue;
            }

            if ($node->hasAttribute('disabled')) {
                // Ignore disabled nodes
                continue;
            }

            yield $name => $node;
        }
    }
1273843
public function nodeListToArray(DOMNodeList $pNodeList)
    {
        $values = array();

        if ($pNodeList === false or ! $pNodeList->length) {
            return $values;
        }

        foreach ($pNodeList as $node) {
            if ($node instanceof DOMElement) {
                if ($node->childNodes and $node->childNodes->length > 1 or ($node->childNodes and $node->childNodes->length == 1 and ! $node->childNodes->item(0) instanceof DOMText)) {
                    $attributes = $this->_getNodeAttributes($node);

                    if (! array_key_exists($node->nodeName, $values)) {
                        if (empty($attributes)) {
                            $values[$node->nodeName] = $this->nodeListToArray($node->childNodes);
                        } else {
                            $values[$node->nodeName] = array_merge($this->nodeListToArray($node->childNodes), $attributes);
                        }
                    } else {
                        if (! is_array($values[$node->nodeName]) or ! array_key_exists(0, $values[$node->nodeName])) {
                            $values[$node->nodeName] = array($values[$node->nodeName]);
                        }

                        if (empty($attributes)) {
                            $values[$node->nodeName][] = $this->nodeListToArray($node->childNodes);
                        } else {
                            $values[$node->nodeName][] = array_merge($this->nodeListToArray($node->childNodes), $attributes);
                        }
                    }
                } else {
                    $attributes = $this->_getNodeAttributes($node);
                    $query = $this->xPathQuery('.//' . $node->nodeName, $node->parentNode);

                    if ($query->length > 1) {
                        if (isset($values[$node->nodeName]) and ! array_key_exists(0, $values[$node->nodeName])) {
                            $values[$node->nodeName] = array($values[$node->nodeName]);
                        }
                        if (empty($attributes)) {
                            $values[$node->nodeName][] = $node->nodeValue;
                        } else {
                            if ($node->nodeValue) {
                                $values[$node->nodeName][] = array_merge(array($node->nodeValue), $attributes);
                            } else {
                                if (isset($values[$node->nodeName]) and is_array($values[$node->nodeName])) {
                                    $values[$node->nodeName][] = $attributes;
                                } else {
                                    $values[$node->nodeName] = $attributes;
                                }
                            }
                        }
                    } else {
                        if (empty($attributes)) {
                            $values[$node->nodeName] = $node->nodeValue;
                        } else {
                            $values[$node->nodeName] = ($node->nodeValue) ? array_merge(array($node->nodeValue), $attributes) : $attributes;
                        }
                    }
                }
            } else if ($node instanceof DOMAttr) {
                if (! array_key_exists($node->name, $values)) {
                    $values[$node->name] = $node->value;
                } else {
                    if (! is_array($values[$node->name])) {
                        $values[$node->name] = array($values[$node->name]);
                    }

                    if (is_array($values[$node->name])) {
                        $values[$node->name][] = $node->value;
                    } else {
                        $values[$node->name] = array($node->value);
                    }
                }
            }
        }

        return $values;
    }
560988
public function merge($elements = []): NodeList {
        if (!is_array($elements)) {
            $elements = $elements->toArray();
        }

        return $this->newNodeList(array_merge($this->toArray(), $elements));
    }
907191
private function getChildren($childNodes)
    {
        $uow = $this->dm->getUnitOfWork();
        $locale = $this->locale ?: $uow->getCurrentLocale($this->document);
        $uow->getPrefetchHelper()->prefetch($this->dm, $childNodes, $locale);

        $childDocuments = [];
        foreach ($childNodes as $childNode) {
            $childDocuments[$childNode->getName()] = $uow->getOrCreateProxyFromNode($childNode, $locale);
        }

        return $childDocuments;
    }
148415
protected function getBlockList(\DOMElement $element) {
    $lines = array();
    $prefix = $element->nodeName == 'ol' ? ' 1. ' : ' - ';
    // Markdown does not support definition lists, convert to ul.
    if ($element->nodeName == 'dl') {
      $newline = TRUE;
      /** @var \DOMElement $child */
      foreach ($element->childNodes as $child) {
        switch ($child->nodeName) {

          case 'dt':
            if ($newline) {
              $lines[] = $prefix . $this->getBlock($child);
            }
            else {
              $lines[count($lines) - 1] .= '<br/>' . $this->getBlock($child);
            }
            $newline = FALSE;
            break;

          case 'dd':
            $lines[count($lines) - 1] .= '<br/>' . $this->getBlock($child);
            $newline = TRUE;
            break;

        }
      }
    }
    else {
      /** @var \DOMElement $child */
      foreach ($element->childNodes as $child) {
        switch ($child->nodeName) {

          case 'li':
            $lines[] = $prefix . $this->getBlock($child);
            break;

        }
      }
    }
    return implode("\n", $lines);
  }
519715
public function getNodeAncestors($maxLevel = 3)
    {
        $ancestors = [];
        $level = 0;

        $node = $this->parentNode;

        while ($node && !($node instanceof DOMDocument)) {
            $ancestors[] = $node;
            $level++;
            if ($level === $maxLevel) {
                break;
            }
            $node = $node->parentNode;
        }

        return $ancestors;
    }
1241004
protected function buildNestedArray(array $nodes = [], $parentId = 0)
    {
        $branch = [];

        if (empty($nodes)) {
            $nodes = $this->allNodes();
        }

        foreach ($nodes as $node) {
            if ($node[$this->parentColumn] === $parentId) {
                $children = $this->buildNestedArray($nodes, $node[$this->getKeyName()]);

                if ($children) {
                    $node['children'] = $children;
                }

                $branch[] = $node;
            }
        }

        return $branch;
    }
748527
public static function nodelist_to_array( \DOMNodeList $list ) {
		$out = [];

		foreach ( $list as $node ) {
			$out[ \spl_object_hash( $node ) ] = $node;
		}

		return $out;
	}