protected function write_answers(array $answers, $qtype) {

        $this->xmlwriter->begin_tag('answers');
        foreach ($answers as $elementname => $elements) {
            foreach ($elements as $element) {
                $answer = $this->convert_answer($element, $qtype);
                // Migrate images in answertext.
                if ($answer['answerformat'] == FORMAT_HTML) {
                    $answer['answertext'] = $this->migrate_files($answer['answertext'], 'question', 'answer', $answer['id']);
                }
                // Migrate images in feedback.
                if ($answer['feedbackformat'] == FORMAT_HTML) {
                    $answer['feedback'] = $this->migrate_files($answer['feedback'], 'question', 'answerfeedback', $answer['id']);
                }
                $this->write_xml('answer', $answer, array('/answer/id'));
            }
        }
        $this->xmlwriter->end_tag('answers');
    }