Reads sections and values of a XML file node, recursivly, and stores pairs in-situ.
@access		protected
@param		XML_Element	$node			Section XML node to read
@param		string		$path			Path to this section
@return		void
423207
protected function loadXmlSection( $node, $path = NULL )
	{
		$path	.= $path ? '.' : '';																//  extend path by delimiter
		foreach( $node as $child )																	//  iterate node children
		{
			$name	= $child->getAttribute( 'name' );												//  get node name of child
			switch( $child->getName() ){															//  dispatch on node name
				case 'section':																		//  section node
					$this->loadXmlSection( $child, $path.$name );									//  load child section
					break;
				case 'value':																		//  pair node
					$type	= 'string';																//  default type: string
					if( $child->hasAttribute( 'type' ) )											//  type attribute is set
						$type	= $child->getAttribute( 'type' );									//  realize type attribute
					$value	= (string) $child;														//  convert node content to value string
					settype( $value, $type );														//  apply type to value
					$this->pairs[$path.$name]	= $value;											//  register pair
					break;
			}
		}
	}
848159
private function compactDimensionGroups( &$nodes, $path = "" )
	{
		if ( $this->includeDefaults ) return;

		foreach ( $nodes as $nodeKey => &$node )
		{
			// If there are no children then its a leaf node so there is nothing to do
			if ( ! isset( $node['children'] ) || count( $node['children'] ) === 0 ) continue;

			// Process nodes recursively
			$this->compactDimensionGroups( $node['children'], "$path/{$node['label']}" );

			if ( isset( $child ) ) unset( $child );

			// Once the child nodes have been processed, compact this node
			// This node will be compacted if there is only one child and that child is the default member
			if ( $node['nodeclass'] === 'dimension' )
			{
				// If its a dimension node does the node have a default member?
				// If there are only non-default children keep this node
				if ( ! isset( $node['hasdefault'] ) || ! $node['hasdefault'] ) continue;

				// If it has a default member is there only one member?
				if ( ! isset( $node['children'] ) ) continue;
				if ( count( $node['children'] ) > 1 ) continue;

				// Is the child the default node?
				// Child may have been set before
				// unset( $child );
				$child = reset( $node['children'] );
				if ( ! isset( $child['default'] ) || ! $child['default'] ) continue;

				$retainChildren = isset( $child['retainchildren'] );
				if ( $retainChildren ) $node['retainchildren'] = true;

				// The child is the only member and it is a default,  It can be removed.
				if ( isset( $child['elements'] ) )
				{
					// Bump the elements of the child up to the current node
					$node['elements'] = $child['elements'];

					if ( ! $retainChildren )
					{
						// Remove the child as a member of 'children' if it exists
						if ( isset( $node['children'][ $child['label'] ] ) )
						{
							unset( $node['children'][ $child['label'] ] );
							unset( $node['children'] );
						}
					}
				}
				else
				{
					$retainChildren = true;
					$node['defaulttext'] = $child['text'];
				}

				if ( $retainChildren )
				{
					// Bump the children up.  This is legit and will not override any other children
					// because the check above confirms this is the only child of $node
					$node['children'] = $child['children'];
					// Child may have been set before
					unset( $child );
					// And reset the parent
					foreach ( $node['children'] as $childKey => &$child )
					{
						$child['parent'] = $node['label'];
					}
				}

				$node['default'] = true;
			}
			elseif ( $node['nodeclass'] === 'member' )
			{
				// If its a member node is it a default member?
				if ( ( ! isset( $node['default'] ) || ! $node['default'] ) &&
					 ! array_reduce( $node['children'], function( $carry, $item ) { return $carry === true ? true : isset( $item['default'] ) && $item['default']; }, false )
				   ) continue;

				// If it's a dimension,then process any children.  If the child is a dimension
				// without children delete it as it has been processed and found to be have
				// only default members.

				foreach ( $node['children'] as $childKey => $child )
				{
					if ( $child['nodeclass'] === 'dimension' && isset( $child['default'] ) && $child['default'] )
					{
						// If the child is the only member and it is a default then it can be removed.
						if ( isset( $child['elements'] ) && count( $child['elements'] ) > 0 ) continue;
						if ( isset( $child['children'] ) && count( $child['children'] ) > 0 ) continue;
						unset( $node['children'][ $childKey ] );
					}
					else if ( $child['nodeclass'] === 'primaryitem' )
					{
						$node['retainchildren'] = true;
					}
				}

				// If there is more than one child or none then move along
				if ( ! isset( $node['children'] ) || count( $node['children'] ) !== 1 ) continue;

				// If there is only one child remaining then if it has elements promote them as elements of this node
				// Child may have been set before
				unset( $child );
				$child = reset( $node['children'] );
				if ( $child['nodeclass'] !== 'primaryitem' )
				{
					if ( $child['nodeclass'] === 'dimension' && isset( $child['children'] ) && count( $child['children'] ) > 1 )
					{
						// Or are all the children non-dimensional (eg primary items)?
						if ( count( array_filter( $child['children'],
							function( $node ) {
								return $node['nodeclass'] === 'dimension' ||
								$node['nodeclass'] === 'member';
							} ) ) !== 0
						)
						continue;
					}

					$retainChildren = isset( $child['retainchildren'] );
					if ( $retainChildren ) $node['retainchildren'] = true;

					if ( isset( $child['elements'] ) && count( $child['elements'] ) > 0 )
					{
						if ( isset( $node['elements'] ) )
						{
							// $node['elements'] = array_merge( $node['elements'], $child['elements'] );
							foreach ( $child['elements'] as $elementKey => $element )
							{
								if ( ! $this->entry_is_unique( $node['elements'], $element, $element['entity'] ) ) continue;
								$node['elements'][] = $element;
							}
						}
						else
						{
							$node['elements'] = $child['elements'];
						}

						if ( ! $retainChildren )
						{
							if ( isset( $node['children'][ $child['label'] ] ) )
							{
								unset( $node['children'][ $child['label'] ] );
								unset( $node['children'] );
							}
						}
					}
					else
					{
						$retainChildren = true;
					}

					if ( $retainChildren )
					{
						$node['children'] = $child['children'];
						// Child may have been set before
						unset( $child );
						foreach ( $node['children'] as $childKey => &$child )
						{
							$child['parent'] = $node['label'];
						}
					}

					$node['default'] = true;
				}
			}
			else
			{
				// The node is not dimension or member so check to see if the only child is a default
				// If it is, remove it.
				if ( ! isset( $node['children'] ) ) continue;
				if ( count( $node['children'] ) === 0 )
				{
					unset( $node['children'] );
					continue;
				}

				// There's more than one so move along
				if ( count( $node['children'] ) > 1 ) continue;

				// Is the child a dimension?
				// unset( $child );
				$child = reset( $node['children'] );
				if ( $child['nodeclass'] !== 'dimension' ) continue;
				if ( isset( $child['children'] ) && count( $child['children'] ) > 1 )
				{
					// Or are all the children non-dimensional (eg primary items)?
					if ( count( array_filter( $child['children'],
						function( $node ) {
							return $node['nodeclass'] === 'dimension' ||
							$node['nodeclass'] === 'member';
						} ) ) !== 0
					)
					continue;
				}

				// OK, is the child a default
				if ( ! isset( $child['hasdefault'] ) || ! isset( $child['default'] ) || ! $child['default'] ) continue;

				$retainChildren = isset( $child['retainchildren'] );

				if ( isset( $child['elements'] ) && count( $child['elements'] ) > 0 )
				{
					if ( isset( $node['elements'] ) )
					{
						// $node['elements'] = array_merge( $node['elements'], $child['elements'] );
						foreach ( $child['elements'] as $elementKey => $element )
						{
							if ( ! $this->entry_is_unique( $node['elements'], $element, $element['entity'] ) ) continue;
							$node['elements'][] = $element;
						}
					}
					else
					{
						$node['elements'] = $child['elements'];
					}

					if ( ! $retainChildren )
					{
						if ( isset( $node['children'][ $child['label'] ] ) )
						{
							unset( $node['children'][ $child['label'] ] );
							unset( $node['children'] );
						}
					}
				}
				else
				{
					$retainChildren = true;
				}

				if ( $retainChildren )
				{
					$node['children'] = $child['children'];
					// Child may have been set before
					unset( $child );
					foreach ( $node['children'] as $childKey => &$child )
					{
						$child['parent'] = $node['label'];
					}
				}

			}
		}
	}
520010
protected function containerToDOM(\DomDocument $doc, \DomNode $node) : void
    {
        foreach ($this->children as $child) {
            $node->appendChild($child->toDOM($doc));
        }
    }
752337
public static function parse($xml, $section = null)
  {
    $parser = new XMLParser($xml);
    if (is_string($section) && !empty($section)) {
      return $parser->getXml()->get($section, true);
    }
    return $parser->getXml();
  }
59695
public static function createFromEdgeRcFile($section = 'default', $path = null)
    {
        if ($section === null) {
            $section = 'default';
        }

        $ini = self::parseEdgeRcFile($path);

        if (!isset($ini[$section])) {
            throw new ConfigException("Section \"$section\" does not exist!");
        }

        $auth = new static();
        $auth->setAuth(
            $ini[$section]['client_token'],
            $ini[$section]['client_secret'],
            $ini[$section]['access_token']
        );

        if (isset($ini[$section]['host'])) {
            $auth->setHost($ini[$section]['host']);
        }

        if (isset($ini[$section]['max-size'])) {
            $auth->setMaxBodySize($ini[$section]['max-size']);
        }

        return $auth;
    }
917296
public function processNode( &$nodes, $path, $callback = null )
	{
		// This is working variable to hold the 'current node'
		if ( isset( $pathNode ) ) unset( $pathNode );

		$pathsParts = explode( '/', $path );
		for ( $i = 0; $i < count( $pathsParts ); $i++ )
		{
			// Should do error checking here.  There's lots to go wrong.
			// Working down the hierarchy using the path components.
			$pathNode =& $nodes[ $pathsParts[ $i ] ];

			// Get the text for the node if not already retrieved
			if ( ! isset( $pathNode['text'] ) )
			{
				// $element_xsd = parse_url( $pathNode['label'], PHP_URL_PATH );
				// $key = "$element_xsd#{$pathNode['taxonomy_element']['id']}";

				$taxonomy = $this->getTaxonomyForXSD( $pathNode['label'] );
				$key = $pathNode['label'];

				$pathNode['text'] = $this->getTaxonomyDescriptionForIdWithDefaults(
					$key,
					isset( $pathNode['preferredLabel'] ) ? $pathNode['preferredLabel'] : null,
					$this->getDefaultLanguage()
				);

				if ( ! $pathNode['text'] )
				{
					$pathNode['text'] = $pathNode['label'];
				}
			}

			$nodes =& $pathNode['children'];
		}

		// $pathnode is now the node to which to add the values
		if ( ! $pathNode ) return false; // Something went wrong

		if ( ! empty( $callback ) )
			$callback( $pathNode );

		return true;
	}
283667
private function addNode($node, $path, $prop)
    {
        foreach ($node as $tag => $value) {
            $prefix = implode('.', $path);

            if ($prefix !== '') {
                $prefix .= '.';
            }

            // Check for attributes
            foreach ($value->attributes() as $attribute => $val) {
                if ($this->collapseAttr) {
                    $prop->setProperty($prefix . "$tag.$attribute", (string) $val);
                } else {
                    $prop->setProperty($prefix . "$tag($attribute)", (string) $val);
                }
            }

            // Add tag
            if (count($value->children())) {
                $this->addNode($value, array_merge($path, [$tag]), $prop);
            } else {
                $val = (string) $value;

                /* Check for * and ** on 'exclude' and 'include' tag / ant seems to do this? could use FileSet here
                if ($tag == 'exclude') {
                }*/

                // When property already exists, i.e. multiple xml tag
                // <project>
                //    <exclude>file/a.php</exclude>
                //    <exclude>file/a.php</exclude>
                // </project>
                //
                // Would be come project.exclude = file/a.php,file/a.php
                $p = empty($prefix) ? $tag : $prefix . $tag;
                $prop->append($p, (string) $val, $this->delimiter);
            }
        }
    }
351412
public function before_path($path) {
        if ($this->path_is_grouped($path) and !isset($this->currentdata[$path])) {
            // If the grouped element itself does not contain any final tags,
            // we would not get any chunk data for it. So we add an artificial
            // empty data chunk here that will be eventually replaced with
            // real data later in {@link self::postprocess_chunk()}.
            $this->currentdata[$path] = array(
                'path' => $path,
                'level' => substr_count($path, '/') + 1,
                'tags' => array(),
            );
        }
        if (!$this->grouped_parent_exists($path)) {
            parent::before_path($path);
        }
    }
1206138
private function parseDefaultsConfig(\DOMElement $element, $path)
    {
        if ($this->isElementValueNull($element)) {
            return;
        }

        // Check for existing element nodes in the default element. There can
        // only be a single element inside a default element. So this element
        // (if one was found) can safely be returned.
        foreach ($element->childNodes as $child) {
            if (!$child instanceof \DOMElement) {
                continue;
            }

            if (self::NAMESPACE_URI !== $child->namespaceURI) {
                continue;
            }

            return $this->parseDefaultNode($child, $path);
        }

        // If the default element doesn't contain a nested "bool", "int", "float",
        // "string", "list", or "map" element, the element contents will be treated
        // as the string value of the associated default option.
        return trim($element->textContent);
    }
132061
static function handleNode( $node, $generator, $level = 0 )
    {
        switch ( $node->localName )
        {
            case "section":
            {
                foreach ( $node->childNodes as $childNode )
                {
                    self::handleNode( $childNode, $generator, $level + 1 );
                }
            } break;

            case "header":
            {
                if ( $level == 0 )
                    $level = 1;

                $paragraphParameters = array();

                $prevLineBreak = false;
                foreach ( $node->childNodes as $childNode )
                {
                    $return = eZOOConverter::handleInlineNode( $childNode, $generator, $prevLineBreak );
                    $paragraphParameters = array_merge( $paragraphParameters,  $return['paragraph_parameters'] );
                    $prevLineBreak = ( $childNode->nodeType === XML_ELEMENT_NODE &&
                                       $childNode->localName === 'line' );
                }
                $generator->addHeader( trim( $node->nodeValue ), $level, $paragraphParameters );
            } break;

            case "ul":
            case "ol":
            {
                self::handleInlineNode( $node, $generator, $level );
            } break;

            case "paragraph":
            {
                $paragraphParameters = array();
                $imageArray = array();

                $prevLineBreak = false;
                foreach ( $node->childNodes as $child )
                {
                    $return = self::handleInlineNode( $child, $generator, $prevLineBreak );
                    $paragraphParameters = array_merge( $paragraphParameters, $return['paragraph_parameters'] );
                    $imageArray = array_merge( $imageArray, $return['image_array'] );

                    $prevLineBreak = ( $child->nodeType === XML_ELEMENT_NODE &&
                                       $child->localName === 'line' );
                }

                foreach ( $imageArray as $image )
                {
                    $generator->addImage( $image );
                }

                if ( !empty( $paragraphParameters ) && isset( $GLOBALS['CustomTagStyle'] ) and $GLOBALS['CustomTagStyle'] != false )
                {
                    array_unshift( $paragraphParameters, $GLOBALS['CustomTagStyle'] );
                }

                call_user_func_array( array( $generator, "addParagraph" ), $paragraphParameters );
            } break;

            default:
            {
                eZDebug::writeError( "Unsupported node for document conversion: " . $node->localName );
            }
        }
    }
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;
    }
638247
protected function _processTree($file, $nodes, $coverage, $path = '')
    {
        foreach ($nodes as $node) {
            $this->_processNode($file, $node, $coverage, $path);
        }
    }
21317
protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void
    {
        $title = htmlspecialchars($node->getTitle());
        $element = $document->createElement(static::NODE_NAME, $title);
        $rootElement->appendChild($element);
    }
1152501
public function saveNode(NodePath $nodePath, array $node)
    {
        $this->data = $this->storeNode($nodePath, $this->data, $node);
    }
1116502
public function setNodeContent($path, $value)
    {
        $node = $this->getNode($path);
        if ($node) {
            while ($node->hasChildNodes()) {
                $node->removeChild($node->firstChild);
            }
            $node->appendChild($this->domDocument->createTextNode($value));
        }
    }
1013545
private function addSchemaOrgSection(ArrayNodeDefinition $node)
    {
        /** @noinspection PhpUndefinedMethodInspection */
        $node
            ->children()
                ->arrayNode('schema_org')
                    ->addDefaultsIfNotSet()
                    ->children()
                        ->arrayNode('provider')
                            ->defaultValue([])
                            ->useAttributeAsKey('name')
                            ->prototype('scalar')->end()
                        ->end()
                    ->end()
                ->end()
            ->end();
    }
985035
public function read($file)
    {
        $this->lines = [];

        $section = '';

        foreach (file($file) as $line) {
            if (preg_match('/^\s*(;.*)?$/', $line)) {
                // comment or whitespace
                $this->lines[] = [
                    'type' => 'comment',
                    'data' => $line,
                    'section' => $section
                ];
            } elseif (preg_match('/^\s?\[(.*)\]/', $line, $match)) {
                // section
                $section = $match[1];
                $this->lines[] = [
                    'type' => 'section',
                    'data' => $line,
                    'section' => $section
                ];
            } elseif (preg_match('/^\s*(.*?)\s*=\s*(.*?)\s*$/', $line, $match)) {
                // entry
                $this->lines[] = [
                    'type' => 'entry',
                    'data' => $line,
                    'section' => $section,
                    'key' => $match[1],
                    'value' => $match[2]
                ];
            }
        }
    }