public function parseInnerTree(array $elementMap = null)
    {
        $text = null;
        $elements = [];

        if (self::ELEMENT === $this->nodeType && $this->isEmptyElement) {
            // Easy!
            $this->next();

            return null;
        }

        if (!is_null($elementMap)) {
            $this->pushContext();
            $this->elementMap = $elementMap;
        }

        try {
            if (!$this->read()) {
                $errors = libxml_get_errors();
                libxml_clear_errors();
                if ($errors) {
                    throw new LibXMLException($errors);
                }
                throw new ParseException('This should never happen (famous last words)');
            }

            while (true) {
                if (!$this->isValid()) {
                    $errors = libxml_get_errors();

                    if ($errors) {
                        libxml_clear_errors();
                        throw new LibXMLException($errors);
                    }
                }

                switch ($this->nodeType) {
                    case self::ELEMENT:
                        $elements[] = $this->parseCurrentElement();
                        break;
                    case self::TEXT:
                    case self::CDATA:
                        $text .= $this->value;
                        $this->read();
                        break;
                    case self::END_ELEMENT:
                        // Ensuring we are moving the cursor after the end element.
                        $this->read();
                        break 2;
                    case self::NONE:
                        throw new ParseException('We hit the end of the document prematurely. This likely means that some parser "eats" too many elements. Do not attempt to continue parsing.');
                    default:
                        // Advance to the next element
                        $this->read();
                        break;
                }
            }
        } finally {
            if (!is_null($elementMap)) {
                $this->popContext();
            }
        }

        return $elements ? $elements : $text;
    }
public function parseInnerTree(array $elementMap = null)
    {
        $text = null;
        $elements = [];

        if (self::ELEMENT === $this->nodeType && $this->isEmptyElement) {
            // Easy!
            $this->next();

            return null;
        }

        if (!is_null($elementMap)) {
            $this->pushContext();
            $this->elementMap = $elementMap;
        }

        try {
            if (!$this->read()) {
                $errors = libxml_get_errors();
                libxml_clear_errors();
                if ($errors) {
                    throw new LibXMLException($errors);
                }
                throw new ParseException('This should never happen (famous last words)');
            }

            while (true) {
                if (!$this->isValid()) {
                    $errors = libxml_get_errors();

                    if ($errors) {
                        libxml_clear_errors();
                        throw new LibXMLException($errors);
                    }
                }

                switch ($this->nodeType) {
                    case self::ELEMENT:
                        $elements[] = $this->parseCurrentElement();
                        break;
                    case self::TEXT:
                    case self::CDATA:
                        $text .= $this->value;
                        $this->read();
                        break;
                    case self::END_ELEMENT:
                        // Ensuring we are moving the cursor after the end element.
                        $this->read();
                        break 2;
                    case self::NONE:
                        throw new ParseException('We hit the end of the document prematurely. This likely means that some parser "eats" too many elements. Do not attempt to continue parsing.');
                    default:
                        // Advance to the next element
                        $this->read();
                        break;
                }
            }
        } finally {
            if (!is_null($elementMap)) {
                $this->popContext();
            }
        }

        return $elements ? $elements : $text;
    }
public function parseInnerTree ( array $ elementMap = null ) { $ text = null ; $ elements = [ ] ; if ( self :: ELEMENT === $ this -> nodeType && $ this -> isEmptyElement ) { // Easy! $ this -> next ( ) ; return null ; } if ( ! is_null ( $ elementMap ) ) { $ this -> pushContext ( ) ; $ this -> elementMap = $ elementMap ; } try { if ( ! $ this -> read ( ) ) { $ errors = libxml_get_errors ( ) ; libxml_clear_errors ( ) ; if ( $ errors ) { throw new LibXMLException ( $ errors ) ; } throw new ParseException ( 'This should never happen (famous last words)' ) ; } while ( true ) { if ( ! $ this -> isValid ( ) ) { $ errors = libxml_get_errors ( ) ; if ( $ errors ) { libxml_clear_errors ( ) ; throw new LibXMLException ( $ errors ) ; } } switch ( $ this -> nodeType ) { case self :: ELEMENT : $ elements [ ] = $ this -> parseCurrentElement ( ) ; break ; case self :: TEXT : case self :: CDATA : $ text .= $ this -> value ; $ this -> read ( ) ; break ; case self :: END_ELEMENT : // Ensuring we are moving the cursor after the end element. $ this -> read ( ) ; break 2 ; case self :: NONE : throw new ParseException ( 'We hit the end of the document prematurely. This likely means that some parser "eats" too many elements. Do not attempt to continue parsing.' ) ; default : // Advance to the next element $ this -> read ( ) ; break ; } } } finally { if ( ! is_null ( $ elementMap ) ) { $ this -> popContext ( ) ; } } return $ elements ? $ elements : $ text ; }
Parses all elements below the current element.

This method will return a string if this was a text-node, or an array if
there were sub-elements.

If there's both text and sub-elements, the text will be discarded.

If the $elementMap argument is specified, the existing elementMap will
be overridden while parsing the tree, and restored after this process.

@return array|string|null
Parses all elements below the current element .