src/XML/Reader.php
public function parseTree(XMLReader $reader)
    {
        libxml_use_internal_errors(true);
        $root = new XMLNode;
        $cur = null;

        $read_anything = false;
        while ($reader->read())
        {
            $read_anything = true;
            if ($reader->nodeType === XMLReader::ELEMENT)
            {
                if ($cur === null)
                {
                    $root->name = $reader->name;
                    $cur = $root;
                }
                else
                {
                    $node = new XMLNode;
                    $node->name = $reader->name;
                    $node->parent = $cur;
                    $cur->children[] = $node;
                    $cur = $node;
                }

                if ($reader->hasAttributes)
                {
                    while ($reader->moveToNextAttribute())
                    {
                        $node = new XMLNode;
                        $node->name = $reader->name;
                        $node->content = $reader->value;
                        $cur->attributes[] = $node;
                    }
                }

            }
            else if ($reader->nodeType === XMLReader::END_ELEMENT)
            {
                $cur = $cur->parent;
            }
            else if ($reader->nodeType === XMLReader::TEXT)
            {
                $cur->content = $reader->value;
            }
        }

        try
        {
            foreach (libxml_get_errors() as $error)
                throw new XMLException($error);
        }
        finally
        {
            libxml_clear_errors();
        }

        return $root;
    }
public function parseTree(XMLReader $reader)
    {
        libxml_use_internal_errors(true);
        $root = new XMLNode;
        $cur = null;

        $read_anything = false;
        while ($reader->read())
        {
            $read_anything = true;
            if ($reader->nodeType === XMLReader::ELEMENT)
            {
                if ($cur === null)
                {
                    $root->name = $reader->name;
                    $cur = $root;
                }
                else
                {
                    $node = new XMLNode;
                    $node->name = $reader->name;
                    $node->parent = $cur;
                    $cur->children[] = $node;
                    $cur = $node;
                }

                if ($reader->hasAttributes)
                {
                    while ($reader->moveToNextAttribute())
                    {
                        $node = new XMLNode;
                        $node->name = $reader->name;
                        $node->content = $reader->value;
                        $cur->attributes[] = $node;
                    }
                }

            }
            else if ($reader->nodeType === XMLReader::END_ELEMENT)
            {
                $cur = $cur->parent;
            }
            else if ($reader->nodeType === XMLReader::TEXT)
            {
                $cur->content = $reader->value;
            }
        }

        try
        {
            foreach (libxml_get_errors() as $error)
                throw new XMLException($error);
        }
        finally
        {
            libxml_clear_errors();
        }

        return $root;
    }
public function parseTree ( XMLReader $ reader ) { libxml_use_internal_errors ( true ) ; $ root = new XMLNode ; $ cur = null ; $ read_anything = false ; while ( $ reader -> read ( ) ) { $ read_anything = true ; if ( $ reader -> nodeType === XMLReader :: ELEMENT ) { if ( $ cur === null ) { $ root -> name = $ reader -> name ; $ cur = $ root ; } else { $ node = new XMLNode ; $ node -> name = $ reader -> name ; $ node -> parent = $ cur ; $ cur -> children [ ] = $ node ; $ cur = $ node ; } if ( $ reader -> hasAttributes ) { while ( $ reader -> moveToNextAttribute ( ) ) { $ node = new XMLNode ; $ node -> name = $ reader -> name ; $ node -> content = $ reader -> value ; $ cur -> attributes [ ] = $ node ; } } } else if ( $ reader -> nodeType === XMLReader :: END_ELEMENT ) { $ cur = $ cur -> parent ; } else if ( $ reader -> nodeType === XMLReader :: TEXT ) { $ cur -> content = $ reader -> value ; } } try { foreach ( libxml_get_errors ( ) as $ error ) throw new XMLException ( $ error ) ; } finally { libxml_clear_errors ( ) ; } return $ root ; }
Parse the XML into an array. This will add all nodes and attributes to
a tree of XML nodes. This is only basic XML flattening, for full-blown
XML support be sure to use a more fully featured solution like SimpleXML

@param XMLReader $reader The reader reading the XML
@return XMLNode The root node
Parse the XML into an array . This will add all nodes and attributes to a tree of XML nodes . This is only basic XML flattening for full - blown XML support be sure to use a more fully featured solution like SimpleXML