protected function write_single_page_xml($page, $prevpageid=0, $nextpageid=0) {
        //mince nextpageid and prevpageid
        $page->data['nextpageid'] = $nextpageid;
        $page->data['prevpageid'] = $prevpageid;

        // write out each page data
        $this->xmlwriter->begin_tag('page', array('id' => $page->id));

        foreach ($page->data as $field => $value) {
            $this->xmlwriter->full_tag($field, $value);
        }

        //effectively on_lesson_answers_end(), where we write out answers for current page.
        $answers = $page->answers;

        $this->xmlwriter->begin_tag('answers');

        $numanswers = count($answers);
        if ($numanswers) { //if there are any answers (possible there are none!)
            if ($numanswers > 3 && $page->data['qtype'] == 5) { //fix only jumpto only for matching question types.
                if ($answers[0]['jumpto'] !== '0' || $answers[1]['jumpto'] !== '0') {
                    if ($answers[2]['jumpto'] !== '0') {
                        $answers[0]['jumpto'] = $answers[2]['jumpto'];
                        $answers[2]['jumpto'] = '0';
                    }
                    if ($answers[3]['jumpto'] !== '0') {
                        $answers[1]['jumpto'] = $answers[3]['jumpto'];
                        $answers[3]['jumpto'] = '0';
                    }
                }
            }
            foreach ($answers as $data) {
                $this->write_xml('answer', $data, array('/answer/id'));
            }
        }

        $this->xmlwriter->end_tag('answers');

        // answers is now closed for current page. Ending the page.
        $this->xmlwriter->end_tag('page');
    }