MEN XML Checker Plugin - Macros


# ASSERT_XML {xml_path} IS VALID USING XSD {xsd_path}

What ?

This macro will verify if an xml file is valid according to a schema (xsd type file).

Underlying instructions :

LOAD {xsd_path} AS __{%%r1}.xsdfile

LOAD {xml_path} AS __xml_{%%r2}.file
CONVERT __xml_{%%r2}.file TO file(param.relativedate) AS __temp_{%%r3}.file
CONVERT __temp_{%%r3}.file TO xml (structured) AS __temp_{%%r4}.xmlfile

ASSERT __temp_{%%r4}.xmlfile IS valid USING __{%%r1}.xsdfile

> Input :

  • {xsd_path} : The name of the schema (xsd type file).
  • {xml_path} : The name of the xml file to verify (xml type file).

Example :

# ASSERT_XML sample-dataset.xml IS VALID USING XSD reference-file.xsd

First file to process :

../../_images/men-xml-checker-macros-assert-xml-1-sample-dataset.png

Second file to process :

../../_images/men-xml-checker-macros-assert-xml-1-reference-file.png

The folder containing the resources to process :

../../_images/men-xml-checker-macros-assert-xml-1-tree.png

SKF script :

../../_images/men-xml-checker-macros-assert-xml-1-script.png


# ASSERT_XML {actual_file} SIMILAIRE TO {expected_file_path} USING {config}

What ?

This macro will verify if an xml file matches another xml. A config file can be used to change the comparison engine.

Underlying instructions :

LOAD {actual_file} AS __actual_{%%r1}.file
LOAD {expected_file_path} AS __expected_{%%r1}.file
CONVERT __expected_{%%r1}.file TO file(param.relativedate) AS __expected_{%%r2}.file
CONVERT __expected_{%%r2}.file TO xml (structured) AS __expected_{%%r3}.xmlfile

CONVERT __actual_{%%r1}.file TO xml (structured) AS __actual_{%%r4}.xmlfile

ASSERT __expected_{%%r3}.xmlfile IS similaire WITH  __actual_{%%r4}.xmlfile USING {config}

> Input :

  • {actual_file} : The name of the file to compare (xml type file).
  • {expected_file_path} : The name of the file to be compared to (xml type file).
  • {config} : The name of the loaded configuration resource (file type resource). It can be used to change the default comparison engine from jaxb to xmlunit, through a ‘comparateur:xmlunit’ entry. The default comparator can also be changed directly with $(comparateur:xmlunit). A xsd resource can be specified here if using the jaxb comparator.

If you are using jaxb (not xmlunit), which is also the default comparator used by the macro if you have not defined the USING clause, a few more steps are necessary.

You need to load and convert an .xsd file and add it to the using clause :

TEST:
LOAD schema.xsd AS schema
CONVERT schema TO xsd(structured) AS convertedSchema
#ASSERT_XML base.xml SIMILAIRE TO to_be_compared.xml USING $(comparateur:jaxb),convertedSchema

Example :

# ASSERT_XML sample-dataset-1.xml SIMILAIRE TO sample-dataset-2.xml USING config-resource.file

First file to process :

../../_images/men-xml-checker-macros-assert-xml-2-sample-dataset-1.png

Second file to process :

../../_images/men-xml-checker-macros-assert-xml-2-sample-dataset-2.png

Third file to process :

../../_images/men-xml-checker-macros-assert-xml-2-config.png

The folder containing the resources to process :

../../_images/men-xml-checker-macros-assert-xml-2-tree.png

SKF script :

../../_images/men-xml-checker-macros-assert-xml-2-script.png

Console output in DEBUG mode :

../../_images/men-xml-checker-macros-assert-xml-2-stacktrace.png