public function expect($rootElementName, $input, string $contextUri = null)
    {
        if (is_resource($input)) {
            // Unfortunately the XMLReader doesn't support streams. When it
            // does, we can optimize this.
            $input = (string) stream_get_contents($input);
        }
        $r = $this->getReader();
        $r->contextUri = $contextUri;
        $r->XML($input, null, $this->options);

        $rootElementName = (array) $rootElementName;

        foreach ($rootElementName as &$rEl) {
            if ('{' !== $rEl[0]) {
                $rEl = '{}'.$rEl;
            }
        }

        $result = $r->parse();
        if (!in_array($result['name'], $rootElementName, true)) {
            throw new ParseException('Expected '.implode(' or ', $rootElementName).' but received '.$result['name'].' as the root element');
        }

        return $result['value'];
    }
public function expect($rootElementName, $input, string $contextUri = null)
    {
        if (is_resource($input)) {
            // Unfortunately the XMLReader doesn't support streams. When it
            // does, we can optimize this.
            $input = (string) stream_get_contents($input);
        }
        $r = $this->getReader();
        $r->contextUri = $contextUri;
        $r->XML($input, null, $this->options);

        $rootElementName = (array) $rootElementName;

        foreach ($rootElementName as &$rEl) {
            if ('{' !== $rEl[0]) {
                $rEl = '{}'.$rEl;
            }
        }

        $result = $r->parse();
        if (!in_array($result['name'], $rootElementName, true)) {
            throw new ParseException('Expected '.implode(' or ', $rootElementName).' but received '.$result['name'].' as the root element');
        }

        return $result['value'];
    }
public function expect ( $ rootElementName , $ input , string $ contextUri = null ) { if ( is_resource ( $ input ) ) { // Unfortunately the XMLReader doesn't support streams. When it // does, we can optimize this. $ input = ( string ) stream_get_contents ( $ input ) ; } $ r = $ this -> getReader ( ) ; $ r -> contextUri = $ contextUri ; $ r -> XML ( $ input , null , $ this -> options ) ; $ rootElementName = ( array ) $ rootElementName ; foreach ( $ rootElementName as & $ rEl ) { if ( '{' !== $ rEl [ 0 ] ) { $ rEl = '{}' . $ rEl ; } } $ result = $ r -> parse ( ) ; if ( ! in_array ( $ result [ 'name' ] , $ rootElementName , true ) ) { throw new ParseException ( 'Expected ' . implode ( ' or ' , $ rootElementName ) . ' but received ' . $ result [ 'name' ] . ' as the root element' ) ; } return $ result [ 'value' ] ; }
Parses a document in full, and specify what the expected root element
name is.

This function works similar to parse, but the difference is that the
user can specify what the expected name of the root element should be,
in clark notation.

This is useful in cases where you expected a specific document to be
passed, and reduces the amount of if statements.

It's also possible to pass an array of expected rootElements if your
code may expect more than one document type.

@param string|string[] $rootElementName
@param string|resource $input
@param string|null     $contextUri

@throws ParseException

@return array|object|string
Parses a document in full and specify what the expected root element name is .