All Projects → sissaschool → Xmlschema

sissaschool / Xmlschema

Licence: mit
XML Schema validator and data conversion library for Python

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Xmlschema

Xmlcoder
Easy XML parsing using Codable protocols in Swift
Stars: ✭ 460 (+128.86%)
Mutual labels:  xml, decoder, encoder
Fuif
Free Universal Image Format
Stars: ✭ 115 (-42.79%)
Mutual labels:  decoder, encoder
Ks265codec
ks cloud hevc(h265) encoder decoder test and description
Stars: ✭ 192 (-4.48%)
Mutual labels:  decoder, encoder
Silk V3 Decoder
kn007's blog
Stars: ✭ 1,832 (+811.44%)
Mutual labels:  decoder, encoder
Polar 3gpp Matlab
Matlab simulations of the encoder and SCL decoder for the New Radio polar code from 3GPP Release 15
Stars: ✭ 67 (-66.67%)
Mutual labels:  decoder, encoder
Alfalfa
Purely functional video codec, used for ExCamera and Salsify
Stars: ✭ 1,164 (+479.1%)
Mutual labels:  decoder, encoder
Swift Html Entities
HTML5 spec-compliant character encoder/decoder for Swift
Stars: ✭ 130 (-35.32%)
Mutual labels:  decoder, encoder
Fast Xml Parser
Validate XML, Parse XML to JS/JSON and vise versa, or parse XML to Nimn rapidly without C/C++ based libraries and no callback
Stars: ✭ 1,021 (+407.96%)
Mutual labels:  xml, validator
Wav
Battle tested Wav decoder/encoder
Stars: ✭ 139 (-30.85%)
Mutual labels:  decoder, encoder
Cityengine Sdk
CityEngine is a 3D city modeling software for urban design, visual effects, and VR/AR production. With its C++ SDK you can create plugins and standalone apps capable to execute CityEngine CGA procedural modeling rules.
Stars: ✭ 137 (-31.84%)
Mutual labels:  decoder, encoder
Base62
Base62 encoder and decoder for arbitrary data
Stars: ✭ 141 (-29.85%)
Mutual labels:  decoder, encoder
Iced
Blazing fast and correct x86/x64 disassembler, assembler, decoder, encoder for .NET, Rust, Python, JavaScript
Stars: ✭ 1,102 (+448.26%)
Mutual labels:  decoder, encoder
Ffjpeg
a simple jpeg codec.
Stars: ✭ 58 (-71.14%)
Mutual labels:  decoder, encoder
Wx Voice
Convert audio files between Tencent apps (Weixin / Wechat, QQ) and Silk codec with other general formats such as MP3 and M4A
Stars: ✭ 93 (-53.73%)
Mutual labels:  decoder, encoder
Reed Solomon
Reed Solomon BCH encoder and decoder
Stars: ✭ 57 (-71.64%)
Mutual labels:  decoder, encoder
Bbwebimage
A high performance Swift library for downloading, caching and editing web images asynchronously.
Stars: ✭ 128 (-36.32%)
Mutual labels:  decoder, encoder
Ffmediatoolkit
FFMediaToolkit is a cross-platform video decoder/encoder library for .NET that uses FFmpeg native libraries. It supports video frames extraction, reading stream metadata and creating videos from bitmaps in any format supported by FFmpeg.
Stars: ✭ 156 (-22.39%)
Mutual labels:  decoder, encoder
Encore
Synonym of angkor
Stars: ✭ 19 (-90.55%)
Mutual labels:  decoder, encoder
Py Ubjson
Universal Binary JSON draft-12 serializer for Python
Stars: ✭ 30 (-85.07%)
Mutual labels:  decoder, encoder
Irremoteesp8266
Infrared remote library for ESP8266/ESP32: send and receive infrared signals with multiple protocols. Based on: https://github.com/shirriff/Arduino-IRremote/
Stars: ✭ 1,964 (+877.11%)
Mutual labels:  decoder, encoder

xmlschema


.. image:: https://img.shields.io/pypi/v/xmlschema.svg :target: https://pypi.python.org/pypi/xmlschema/ .. image:: https://img.shields.io/pypi/pyversions/xmlschema.svg :target: https://pypi.python.org/pypi/xmlschema/ .. image:: https://img.shields.io/pypi/implementation/xmlschema.svg :target: https://pypi.python.org/pypi/xmlschema/ .. image:: https://img.shields.io/badge/License-MIT-blue.svg :alt: MIT License :target: https://lbesson.mit-license.org/ .. image:: https://travis-ci.org/sissaschool/xmlschema.svg?branch=master :target: https://travis-ci.org/sissaschool/xmlschema .. image:: https://img.shields.io/pypi/dm/xmlschema.svg :target: https://pypi.python.org/pypi/xmlschema/ .. image:: https://img.shields.io/badge/Maintained%3F-yes-green.svg :target: https://GitHub.com/Naereen/StrapDown.js/graphs/commit-activity

.. xmlschema-introduction-start

The xmlschema library is an implementation of XML Schema <http://www.w3.org/2001/XMLSchema>_ for Python (supports Python 3.6+).

This library arises from the needs of a solid Python layer for processing XML Schema based files for MaX (Materials design at the Exascale) <http://www.max-centre.eu>_ European project. A significant problem is the encoding and the decoding of the XML data files produced by different simulation software. Another important requirement is the XML data validation, in order to put the produced data under control. The lack of a suitable alternative for Python in the schema-based decoding of XML data has led to build this library. Obviously this library can be useful for other cases related to XML Schema based processing, not only for the original scope.

The full xmlschema documentation is available on "Read the Docs" <http://xmlschema.readthedocs.io/en/latest/>_.

Features

This library includes the following features:

  • Full XSD 1.0 and XSD 1.1 support
  • Building of XML schema objects from XSD files
  • Validation of XML instances against XSD schemas
  • Decoding of XML data into Python data and to JSON
  • Encoding of Python data and JSON to XML
  • Data decoding and encoding ruled by converter classes
  • An XPath based API for finding schema's elements and attributes
  • Support of XSD validation modes strict/lax/skip
  • Remote attacks protection by default using an XMLParser that forbids entities
  • XML data bindings based on DataElement class (experimental)
  • Static code generation with Jinja2 templates (experimental)

Installation

You can install the library with pip in a Python 3.6+ environment::

pip install xmlschema

The library uses the Python's ElementTree XML library and requires elementpath <https://github.com/brunato/elementpath>_ additional package. The base schemas of the XSD standards are included in the package for working offline and to speed-up the building of schema instances.

.. xmlschema-introduction-end

Usage

Import the library and then create a schema instance using the path of the file containing the schema as argument:

.. code-block:: pycon

>>> import xmlschema
>>> my_schema = xmlschema.XMLSchema('tests/test_cases/examples/vehicles/vehicles.xsd')

.. note:: For XSD 1.1 schemas use the class XMLSchema11, because the default class XMLSchema is an alias of the XSD 1.0 validator class XMLSchema10.

The schema can be used to validate XML documents:

.. code-block:: pycon

>>> my_schema.is_valid('tests/test_cases/examples/vehicles/vehicles.xml')
True
>>> my_schema.is_valid('tests/test_cases/examples/vehicles/vehicles-1_error.xml')
False
>>> my_schema.validate('tests/test_cases/examples/vehicles/vehicles-1_error.xml')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/brunato/Development/projects/xmlschema/xmlschema/validators/xsdbase.py", line 393, in validate
    raise error
xmlschema.validators.exceptions.XMLSchemaValidationError: failed validating <Element '{http://example.com/vehicles}cars' at 0x7f8032768458> with XsdGroup(model='sequence').

Reason: character data between child elements not allowed!

Schema:

  <xs:sequence xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element maxOccurs="unbounded" minOccurs="0" name="car" type="vh:vehicleType" />
  </xs:sequence>

Instance:

  <vh:cars xmlns:vh="http://example.com/vehicles">
    NOT ALLOWED CHARACTER DATA
    <vh:car make="Porsche" model="911" />
    <vh:car make="Porsche" model="911" />
  </vh:cars>

Using a schema you can also decode the XML documents to nested dictionaries, with values that match to the data types declared by the schema:

.. code-block:: pycon

>>> import xmlschema
>>> from pprint import pprint
>>> xs = xmlschema.XMLSchema('tests/test_cases/examples/collection/collection.xsd')
>>> pprint(xs.to_dict('tests/test_cases/examples/collection/collection.xml'))
{'@xsi:schemaLocation': 'http://example.com/ns/collection collection.xsd',
 'object': [{'@available': True,
             '@id': 'b0836217462',
             'author': {'@id': 'PAR',
                        'born': '1841-02-25',
                        'dead': '1919-12-03',
                        'name': 'Pierre-Auguste Renoir',
                        'qualification': 'painter'},
             'estimation': Decimal('10000.00'),
             'position': 1,
             'title': 'The Umbrellas',
             'year': '1886'},
            {'@available': True,
             '@id': 'b0836217463',
             'author': {'@id': 'JM',
                        'born': '1893-04-20',
                        'dead': '1983-12-25',
                        'name': 'Joan Miró',
                        'qualification': 'painter, sculptor and ceramicist'},
             'position': 2,
             'title': None,
             'year': '1925'}]}

Authors

Davide Brunato and others who have contributed with code or with sample cases.

License

This software is distributed under the terms of the MIT License. See the file 'LICENSE' in the root directory of the present distribution, or http://opensource.org/licenses/MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].