'Construct an XML string for a capa response
based on **kwargs.
**kwargs is a dictionary that will be passed
to create_response_element() and create_input_element().
See the subclasses below for other keyword arguments
you can specify.
For all response types, **kwargs can contain:
*question_text*: The text of the question to display,
wrapped in <label> tags.
*explanation_text*: The detailed explanation that will
be shown if the user answers incorrectly.
*script*: The embedded Python script (a string)
*num_responses*: The number of responses to create [DEFAULT: 1]
*num_inputs*: The number of input elements
to create [DEFAULT: 1]
*credit_type*: String of comma-separated words specifying the
partial credit grading scheme.
Returns a string representation of the XML tree.'

def build_xml(self, **kwargs):

    question_text = kwargs.get('question_text', '')
    explanation_text = kwargs.get('explanation_text', '')
    script = kwargs.get('script', None)
    num_responses = kwargs.get('num_responses', 1)
    num_inputs = kwargs.get('num_inputs', 1)
    credit_type = kwargs.get('credit_type', None)
    root = etree.Element('problem')
    if script:
        script_element = etree.SubElement(root, 'script')
        script_element.set('type', 'loncapa/python')
        script_element.text = str(script)
    for __ in range(int(num_responses)):
        response_element = self.create_response_element(**kwargs)
        if (credit_type is not None):
            response_element.set('partial_credit', str(credit_type))
        root.append(response_element)
        question = etree.SubElement(response_element, 'label')
        question.text = question_text
        for __ in range(int(num_inputs)):
            input_element = self.create_input_element(**kwargs)
            if (not (None == input_element)):
                response_element.append(input_element)
        if explanation_text:
            explanation = etree.SubElement(root, 'solution')
            explanation_div = etree.SubElement(explanation, 'div')
            explanation_div.set('class', 'detailed-solution')
            explanation_div.text = explanation_text
    return etree.tostring(root)
