How to use DATEX II supported validation to:
🚀 speed up 🚀
system design and development
deployment and operation
fixing problems
📈 improve 📈
quality of data exchange
jan.vlcinsky@tamtamresearch.com
Executive Researcher at TamTam Research, Czechia
featuring
Validation Concepts and Context,
Local Validators
and Daily Validations of published data (InQMS)
Data Analyst at Austriatech, Austria
featuring
On-line class model validator at RAV Centre
Information Architect at Nationaal Dataportaal Wegverkeer (NDW), The Netherlands
featuring
On-line serialized message validator at NDW
DATEX II Context and Concepts for validation
Tools and demo:
on-line DATEX II RAV Center class model validator
local message validators
on-line message validator at NDW
InQMS: daily message validations of Czech content
—
Validate to fix things faster
by Jan Vlčinský, TamTam Research
by Andreas Dis, Austriatech
—
DATEX II RAV Center (on-line) class model validator
RAV = Reference Advice and Validation https://testcenter.datex2.eu/xmlchk/
Currently validates: profiles against Commission’s Delegated Regulations (EU) reference profile on secure truck parking information (No 885/2013) in DATEX II Version 2.3.
by Jan Vlčinský, TamTam Research
Use cases and value for publisher and consumer
Publishing a schema within an hour
JSON/XML/ASN.1 schema types
XML validators: local/desktop/on-line
Message validation
Code generation
Lack of
relevant XML/JSON/ASN.1 Schema
☠ KILLS all the benefits ☠
—
This is where NAP plays the key role.
Directory Content:
schema/schema.xsd # mission accomplished!!! samples/*.xml # nice to have FORMAT.yaml # metadata sel/fname.sel # optional
There are multiple JSON Schema variants:
[X]
JSON Schema Draft 4[ ]
JSON Schema Draft 5[ ]
JSON Schema Draft 6[ ]
JSON Schema Draft 7[ ]
JSON Draft 2019-09[ ]
JSON Draft 2020-12—
DATEX II uses Draft 4
There are multiple XML Schema variants:
[X]
W3C XML Schema v1.0[ ]
W3C XML Schema v1.1[ ]
RELAX NG (XML and Compact Syntax)[ ]
Schematron—
DATEX II uses W3C XML Schema v1.0
💻 | Desktop: Altova XMLSpy, oXygen XML Editor, Stylus Studio, Liquid XML Studio, XMLPad, Exchanger XML Editor |
🎹 | CLI: xmlstarlet, xmllint, Xerces-C++ XML Parser, MSV, Saxon |
📜 | Code: pytest test case using lxml lib; +∞ |
You will find one or more for sure
$ xmlstarlet val \ --xsd schema/schema.xsd \ samples/message.xml $ xmllint \ --schema schema/schema.xsd \ samples/message.xml $ java -jar msv.jar \ schema/schema.xsd \ samples/message.xml $ java -jar saxon9he.jar \ -s:samples/message.xml \ -xsd:schema/schema.xsd \ -val:strict $ XercesCParser -v -s -n \ samples/message.xml # schema referenced within message.xml
xmlstarlet
CLI for XMLBased on libxml2 (as xmllint or python lxml library)
Runs on Windows, Linux, MacOS..:
$ # validate single file: $ xmlstarlet val --xsd schema/schema.xsd --err sample/message.xml $ # validate multiple files $ xmlstarlet val --xsd schema/schema.xsd sample/*.xml $ # list only invalid files $ xmlstarlet val --xsd schema/schema.xsd --list-bad sample/*.xml
xmlstarlet
via docker (Linux)Pull and tag the docker image (once)
$ export IMAGE_URL=registry.gitlab.com/datex2/presentation/2023-virtduf-validation/xmlstarlet-docker:1.0.0 $ docker pull $IMAGE_URL # pull the image $ docker image tag $IMAGE_URL xmlstarlet # and tag it e.g. as xmlstarlet
Use it for validation
$ docker run -it --rm -v $PWD:/data xmlstarlet \ val --err \ --xsd schema/schema.xsd \ samples/accident.xml samples/accident.xml - valid
https://gitlab.com/datex2/presentation/2023-virtduf-validation/xmlstarlet-docker
xmlstarlet
via docker (Windows)Pull and tag the docker image (once)
C:\DATEX2>set IMAGE_URL=registry.gitlab.com/datex2/presentation/2023-virtduf-validation/xmlstarlet-docker:1.0.0 C:\DATEX2>docker pull %IMAGE_URL% C:\DATEX2>docker image tag %IMAGE_URL% xmlstarlet
Use it for validation
C:\DATEX2>docker run -it --rm -v %cd%:/data xmlstarlet ^ val --err ^ --xsd schema/schema.xsd ^ samples/accident.xml samples/accident.xml - valid
https://gitlab.com/datex2/presentation/2023-virtduf-validation/xmlstarlet-docker
pytest
test case example (Python)Conformance to a schema is crucial
Let your code do the work
Detects errors before committing the code
Makes code refactoring real fun
Example for Python
https://gitlab.com/datex2/presentation/2023-virtduf-validation/pytest-validate
from pathlib import Path from lxml import etree import pytest
tests/test_validate.py: messages to test
@pytest.fixture( params=[ "samples/accident.xml", "samples/brokendownvehicles.xml", "samples/restriction-bkom.xml", "samples/invalid_missig_lang.xml", ] ) def message(request): """Parsed XML message (as lxml tree instance)""" path = Path(request.param) assert path.exists() xml_doc = etree.parse(str(path)) return xml_doc
tests/test_validate.py: schema to use
@pytest.fixture def schema(): """W3C XML Schema (lxml XMLSchema instance)""" path = Path("schema/schema.xsd") assert path.exists() xsd_doc = etree.parse(path) xml_schema = etree.XMLSchema(xsd_doc) return xml_schema
tests/test_validate.py: actual test
def test_validate(schema, message): """Test that the `message` conforms to `schema`""" assert schema.validate(message), f"Invalid: {schema.error_log}"
call the test
$ pdm run pytest -sv tests
and see the test report: header
============================= test session starts ==============================
platform linux -- Python 3.11.4, pytest-7.4.2, pluggy-1.3.0 -- /home/javl/devel/datex2/gitlab/presentation/2023-virtduf-validation/pytest-validate/.venv/bin/python
cachedir: .pytest_cache
rootdir: /home/javl/devel/datex2/gitlab/presentation/2023-virtduf-validation/pytest-validate
collecting ... collected 4 items
...
test report: Short summary test results
... collecting ... collected 4 items tests/test_validate.py::test_validate[samples/accident.xml] PASSED tests/test_validate.py::test_validate[samples/brokendownvehicles.xml] PASSED tests/test_validate.py::test_validate[samples/restriction-bkom.xml] PASSED tests/test_validate.py::test_validate[samples/invalid_missig_lang.xml] FAILED =================================== FAILURES ===================================
test report: Detailed failure description
... =================================== FAILURES =================================== ________________ test_validate[samples/invalid_missig_lang.xml] ________________ schema = <lxml.etree.XMLSchema object at 0x7ffb1e93f9c0> message = <lxml.etree._ElementTree object at 0x7ffb1e995740> def test_validate(schema, message): > assert schema.validate(message), f"Invalid: {schema.error_log}" E AssertionError: Invalid: samples/invalid_missig_lang.xml:11:0:ERROR:SCHEMASV:SCHEMAV_CVC_COMPLEX_TYPE_4: Element '{http://datex2.eu/schema/2/2_0}payloadPublication': The attribute 'lang' is required but missing. E assert False E + where False = <bound method _Validator.validate of <lxml.etree.XMLSchema object at 0x7ffb1e93f9c0>>(<lxml.etree._ElementTree object at 0x7ffb1e995740>) E + where <bound method _Validator.validate of <lxml.etree.XMLSchema object at 0x7ffb1e93f9c0>> = <lxml.etree.XMLSchema object at 0x7ffb1e93f9c0>.validate tests/test_validate.py:33: AssertionError =========================== short test summary info ============================
test report: short test summary info
=========================== short test summary info ============================ FAILED tests/test_validate.py::test_validate[samples/invalid_missig_lang.xml] ========================= 1 failed, 3 passed in 0.08s ==========================
https://gitlab.com/datex2/presentation/2023-virtduf-validation/pytest-validate
by Edgar van Wilgenburg, NDW
—
On-line XML message validation
for selected DATEX II Profiles
Stop expensive exchanges of structurally broken data
Quick and Easy (On-Line) Validation
Directory of Agreed profiles
Accessible to All types of Users
Python + Flask web app (+ Bash + xmllint).
For DATEX II XML messages.
Accepts gzipped files.
Checks for: schema defined structure.
Let’s meet our on-line Gandalf
Repeat for valid/invalid DATEX II Message
very easy to use
very clear answer (one of):
you are fine or list of things to fix
by Jan Vlčinský, TamTam Research
—
Let’s try to
validate
all the published messages
https://inqms.tamtamresearch.com/
—
Tested with Czech NDIC content.
List all the published messages:
—
Makes resolving data exchange problem much simpler.
Time series for:
Slides
https://slides-datex2-presentation-2023-virtduf-validati-23493b76d5a303.gitlab.io/
https://gitlab.com/datex2/presentation/2023-virtduf-validation:
RAV Centre
https://testcenter.datex2.eu/xmlchk/
NDW On-line DATEX II Validator
https://d2val.staging.ndw.nu/
Proof of concepts for publishing DATEX II extensions and profiles.
This is not an official DATEX II site.
Includes also materials for this presentation.
Command line utility to query, transform, validate, and edit XML documents and files using a simple set of shell commands in a way similar to how it is done with grep, sed, awk, diff, patch, join, etc.
https://xmlstar.sourceforge.net/
OS: Unix-like, Windows, CygWin, Mac OS
Wikipedia: https://en.wikipedia.org/wiki/XMLStarlet
director/writer: Kurt Kuenne
YouTube: Validation by Kurt Kuenne (16:23)
You are Awesome!!!