Ejemplo n.º 1
0
def check_xml(xml_path, xml_ns, schema_type, schema_dcp):
    # Correct file type (magic number)
    xml_magic = magic.from_file(xml_path)
    if "XML" not in xml_magic:
        raise CheckException(
            "File type unknown, expected XML Document but got {}".format(
                xml_magic))

    # Correct namespace
    schema_id = get_schema(xml_ns)
    if not schema_id:
        raise CheckException("Namespace unknown : {}".format(xml_ns))

    # Coherence with package schema
    if schema_type != schema_dcp:
        raise CheckException(
            "Schema is not valid got {} but was expecting {}".format(
                schema_type, schema_dcp))

    # XSD schema validation
    try:
        validate_xml(xml_path, schema_id)
    except LookupError as e:
        get_log().info("Schema validation skipped : {}".format(xml_path))
    except Exception as e:
        raise CheckException("Schema validation error : {}".format(str(e)))
Ejemplo n.º 2
0
def check_xml(xml_path, xml_ns, schema_type, schema_dcp):
    # Correct namespace
    schema_id = get_schema(xml_ns)
    if not schema_id:
        raise CheckException("Namespace unknown : {}".format(xml_ns))

    # Coherence with package schema
    if schema_type != schema_dcp:
        raise CheckException(
            "Schema is not valid got {} but was expecting {}".format(
                schema_type, schema_dcp))

    # XSD schema validation
    try:
        validate_xml(xml_path, schema_id)
    except LookupError as e:
        get_log().info("Schema validation skipped : {}".format(xml_path))
    except Exception as e:
        raise CheckException("Schema validation error : {}".format(str(e)))
Ejemplo n.º 3
0
def check_xml(checker, xml_path, xml_ns, schema_type, schema_dcp):
    # XML constraints
    check_xml_constraints(checker, xml_path)

    # Correct namespace
    schema_id = get_schema(xml_ns)
    if not schema_id:
        checker.error("Namespace unknown : {}".format(xml_ns), "namespace")

    # Coherence with package schema
    if schema_type != schema_dcp:
        message = "Schema is not valid got {} but was expecting {}".format(
            schema_type, schema_dcp)
        checker.error(message, "schema_coherence")

    # XSD schema validation
    try:
        validate_xml(xml_path, schema_id)
    except LookupError as e:
        get_log().info("Schema validation skipped : {}".format(xml_path))
    except Exception as e:
        message = ("Schema validation error : {}\n"
                   "Using schema : {}".format(str(e), schema_id))
        checker.error(message, "schema_validation")