This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

This is an implementation of XML Schema for Python (supports versions 2.7 and Python 3).

Features

  • Builds XML schema objects from XSD files
  • Validates the XML instances with the XSD schema
  • Converts XML instances into Python dictionaries
  • Provides decoding and encoding APIs for XML’s elements and attributes

Installation and usage

You can install the library with:

pip install xmlschema

then you can import the library:

import xmlschema

and create an instance of a schema with:

my_schema = xmlschema.XMLSchema(<path to your XSD schema file>)

Validation

Using a XMLSchema object you can validate XML files based on that schema:

my_schema.is_valid(<path to an XML file based on your XSD schema>)  # returns True or False

If you prefer to raise an exception when the XML file is not validated you can choose another call:

my_schema.validate(<path to an XML file based on your XSD schema>)

If you need to validate only once a file with a particular schema you can use the module’s call:

xmlschema.validate(<path to the XML file>, <path to XSD schema file>)

Data decode and encode

A schema object includes APIs for decoding and encoding the XSD types defined in the schema:

my_schema.types[<XSD type name>].decode(<XML text>)       # Decode XML text or elem to data
my_schema.types[<XSD type name>].encode(<data instance>)  # Decode a data to and XML text

You can also convert the entire XML document to a nested dictionary with data conversion:

my_schema = xmlschema.XMLSchema(<path to your XSD schema file>)
my_schema.to_dict(<path to an XML file based on your XSD schema>)

Running Tests

The package uses the Python’s unitest library. The tests are located in the directory tests/. There are three scripts to test the package:

tests/test_schemas.py
Tests about parsing of XSD Schemas
tests/test_validation.py
Tests about XML validation
tests/test_decoding.py
Tests regarding XML data decoding

There are only some basic tests published on xmlschema’s GitHub repository, but you can add your own tests in a subdirectory as a Git module:

git clone https://github.com/brunato/xmlschema.git
mkdir xmlschema/xmlschema/tests/extra-schemas
cd xmlschema/xmlschema/tests/extra-schemas
git init
touch testfiles

Add to this file the relative or absolute paths of files to be tested, one per line. The file path maybe followed by the number of errors that have to be found in the XML to pass the test.

Release Notes

This release conforming to XML Schema version 1.0, but maybe extended to 1.1 in nearly future releases. Maybe soon will be available a manual for users and developers.

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.

Release History

Release History

0.9.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.8.1b5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.8.1b4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.8b4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.8b3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.8b2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
xmlschema-0.9.1-py2.py3-none-any.whl (98.1 kB) Copy SHA256 Checksum SHA256 py2.py3 Wheel Feb 18, 2017
xmlschema-0.9.1.tar.gz (76.1 kB) Copy SHA256 Checksum SHA256 Source Feb 18, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting