public function next()
    {
        if ($this->trailCount > 0) {

            while ($this->trailCount > 0) {
                $trailEntry = $this->popFromTrail();
                $component = $trailEntry[1];
                $source = $trailEntry[0];

                if ($this->isTraversed($component) === false) {
                    $this->currentComponent = $component;
                    $this->currentContainer = $source;
                    $this->pushOnTrail($component, $this->currentComponent->getComponents());
                    $this->markTraversed($this->currentComponent);

                    if (empty($this->classes) === true || in_array($this->currentComponent->getQTIClassName(), $this->classes) === true) {
                        // If all classes are seeked or the current component has a class name
                        // that must be seeked, stop the iteration.
                        return;
                    }
                }
            }

            $this->isValid = false;
            $this->currentContainer = null;
        } else {
            $this->isValid = false;
            $this->currentContainer = null;
        }
    }