Skip to content

Commit

Permalink
Provide SDMX-ML validation docs
Browse files Browse the repository at this point in the history
  • Loading branch information
goatsweater committed Jan 3, 2024
1 parent e34c18c commit 3d1b2ec
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/howto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ On other pages:
:maxdepth: 1

howto/create
howto/validate

Access other SDMX data sources
------------------------------
Expand Down
44 changes: 44 additions & 0 deletions doc/howto/validate.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Validate SDMX-ML against official schemas
*****************************************

:mod:`sdmx` is capable of generating XML for all kinds of SDMX components. When communicating with remote services
though, only valid SDMX-ML messages can be sent. To help ensure your generated XML complies with the standard you can
call :func:`sdmx.validate_xml`.

Validation requires having a copy of the `official schema <https://github.com/sdmx-twg/sdmx-ml-v2_1>`_ files available.
To help make this easier, you can use :func:`sdmx.install_schemas`, which will cache a local copy for use in validation.

Cache schema files
==================

.. note:: This only needs to be run once.

.. ipython:: python
import sdmx
sdmx.install_schemas()
The schema files will be downloaded and placed in your local cache directory.

Validate SDMX-ML messages
=========================

Generate an SDMX-ML message, perhaps by following :doc:`create`. Once you have a file on disk that has an SDMX-ML
message it can be validated by running :func:`sdmx.validate_xml`. These instructions will use the samples provided by
the `SDMX technical working group <https://github.com/sdmx-twg/sdmx-ml-v2_1>`_.

.. code-block:: python
import sdmx
sdmx.validate_xml("samples/common/common.xml")
True
sdmx.validate_xml("samples/demography/demography.xml")
True
Invalid messages will return ``False``. You will also see a log message to help in tracing the problem::

Element '{http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common}Annotations': This element is not expected.
Expected is one of ( {http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common}Description,
{http://www.sdmx.org/resources/sdmxml/schemas/v2_1/structure}Structure )., line 17

0 comments on commit 3d1b2ec

Please sign in to comment.