protected function expectEndTag($reader, $expectedTag)
    {
        $node = $this->readNode($reader);

        $type = $node->nodeType;
        if ($type !== \XMLReader::END_ELEMENT) {
            $type = isset(self::$types[$type]) ? self::$types[$type] : "#$type";
            throw new \InvalidArgumentException(
                "Expected a closing $expectedTag tag ".
                "but got a node of type $type instead"
            );
        }

        $readTag = $node->name;
        if ($readTag !== $expectedTag) {
            throw new \InvalidArgumentException(
                "Got closing tag for $readTag instead of $expectedTag"
            );
        }

        $this->prepareNextNode();
    }