public function readerLoop($reader)
    {
        $tree = new \stdClass();

        while ($reader->read()) {
            switch ($reader->nodeType) {
                case \XMLReader::END_ELEMENT:
                    return $tree;
                    break;
                case \XMLReader::ELEMENT:
                    $this->processElement($reader, $tree);

                    if ($reader->hasAttributes) {
                        $this->processAttributes($reader, $tree);
                    }
                    break;
                case \XMLReader::TEXT:
                case \XMLReader::CDATA:
                    $tree = \Genesis\Utils\Common::stringToBoolean(
                        trim($reader->expand()->textContent)
                    );
                    break;
            }
        }

        return $tree;
    }