Skip to content
Snippets Groups Projects
user avatar
wactbprot authored
692dd60f
History

xml-validation

HTML-Server written in Python for validation of xml (e.g. DCC xml) against a XML Schema.

Notizen

»lxml« und »xmllint« verwenden beide die Linux/Unix-Bibliotheken »libxml2« und »libxslt«.

Hinweise zur Python-Bibliothek »lxml«

Hinweise zur Python-Bibliothek »xmlschema«

Hinweise zu »xmllint«

xmllint --noout --schema DCC_v1.8.1.xsd 11044_17_DCC_v1.8.1_Au.xml
xmllint --valid --noout 11044_17_DCC_v1.8.1_Au.xml

Installation

> git clone git@a75436.berlin.ptb.de:vaclab/xml-validation.git
> cd xml-validation
> python3 -m venv .
> source bin/activate
> pip install flask flask_cors xmlschema requests GitPython
> ./server

API

/validate endpoint [POST]

> curl -X POST -H "Content-Type: text/xml" -d @valid_xml_matches_xsd http://localhost:5005/validate
> <ok/>
> curl -X POST -H "Content-Type: text/xml" -d @no_valid_xml http://localhost:5005/validate
> <error>unvalid xml data</error>
> curl -X POST -H "Content-Type: text/xml" -d @valid_xml_but_dont_matches_xsd http://localhost:5005/validate
> <error>verbose error message</error>

Example:

> curl -X POST -H "Content-Type: text/xml" -d @11044_17_DCC_v1.8.1_Au_with_error.xml http://localhost:5005/validate
> <error>failed decoding 'A' with XsdAtomicBuiltin(name='xs:double'):

Reason: could not convert string to float: 'A'

Schema:

  <simpleType xmlns="http://www.w3.org/2001/XMLSchema" xmlns:hfp="http://www.w3.org/2001/XMLSchema-hasFacetAndProperty" id="double" name="double">
    <annotation>
      <appinfo>
        <hfp:hasFacet name="pattern" />
        <hfp:hasFacet name="enumeration" />
        <hfp:hasFacet name="whiteSpace" />
        <hfp:hasFacet name="maxInclusive" />
        <hfp:hasFacet name="maxExclusive" />
        <hfp:hasFacet name="minInclusive" />
        <hfp:hasFacet name="minExclusive" />
        <hfp:hasProperty name="ordered" value="total" />
        <hfp:hasProperty name="bounded" value="true" />
        <hfp:hasProperty name="cardinality" value="finite" />
        <hfp:hasProperty name="numeric" value="true" />
      </appinfo>
      <documentation source="http://www.w3.org/TR/xmlschema-2/#double" />
    </annotation>
    <restriction base="xs:anySimpleType">
      <whiteSpace fixed="true" id="double.whiteSpace" value="collapse" />
    </restriction>
  </simpleType>

Instance:

  <ns0:coverageProbability xmlns:ns0="https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/SI">A</ns0:coverageProbability>

Path: /{https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/DCC}digitalCalibrationCertificate/{https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/DCC}measurementResults/{https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/DCC}influenceConditions/{https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/DCC}influenceCondition/{https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/DCC}outcome/{https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/DCC}data/{https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/DCC}quantity/{https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/SI}list/{https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/SI}coverageProbability
</error>

/version [GET]

Returns the version of the validation server:

> curl http://localhost:5005/version
> <version>0.2.0</version>

/update [POST]

Updates the server; used by webhook (no security checks so far).