Exemple #1
0
def validate_xml_data(request):
    # template_id = request.session['currentTemplateID']
    try:
        xsd_tree_str = str(request.session['xmlDocTree'])

        form_id = request.session['form_id']
        root_element = SchemaElement.objects.get(pk=form_id)

        xml_renderer = XmlRenderer(root_element)
        xml_data = xml_renderer.render()

        # validate XML document
        common.validateXMLDocument(xml_data, xsd_tree_str)
    except etree.XMLSyntaxError as xse:
        # xmlParseEntityRef exception: use of & < > forbidden
        message = "Validation Failed. </br> May be caused by : </br> - Syntax problem </br> - Use of forbidden symbols : '&' or '<' or '>'"
        response_dict = {'errors': message}
        return HttpResponse(json.dumps(response_dict),
                            content_type='application/javascript')
    except Exception as e:
        message = e.message.replace('"', '\'')
        response_dict = {'errors': message}
        return HttpResponse(json.dumps(response_dict),
                            content_type='application/javascript')

    return HttpResponse(json.dumps({}), content_type='application/javascript')
def validate_xml_data(request):
    # template_id = request.session['currentTemplateID']
    request.session['xmlString'] = ""
    try:
        xsd_tree_str = str(request.session['xmlDocTree'])

        # set namespaces information in the XML document
        # xmlString = request.POST['xmlString']
        form_id = request.session['form_id']
        root_element = SchemaElement.objects.get(pk=form_id)

        xml_renderer = XmlRenderer(root_element)
        xml_data = xml_renderer.render()

        # xmlString = request.POST['xmlString']
        # validate XML document
        common.validateXMLDocument(xml_data, xsd_tree_str)
    except etree.XMLSyntaxError as xse:
        # xmlParseEntityRef exception: use of & < > forbidden
        message = "Validation Failed. </br> May be caused by : </br> - Syntax problem </br> - Use of forbidden symbols : '&' or '<' or '>'"
        response_dict = {'errors': message}
        return HttpResponse(json.dumps(response_dict), content_type='application/javascript')
    except Exception as e:
        message = e.message.replace('"', '\'')
        response_dict = {'errors': message}
        return HttpResponse(json.dumps(response_dict), content_type='application/javascript')

    # request.session['xmlString'] = xmlString
    # request.session['formString'] = request.POST['xsdForm']

    return HttpResponse(json.dumps({}), content_type='application/javascript')