Giter Site home page Giter Site logo

ainaleke / python-easyxsd Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gnrfan/python-easyxsd

0.0 2.0 0.0 148 KB

Easy XML Schema Definition (XSD) validation of XML documents

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%

python-easyxsd's Introduction

EasyXSD

Easy XML Schema Definition (XSD) validation of XML documents based on lxml.

Usage:

>>> from easyxsd import *
>>> xsd = xsd_from_file('/path/to/files/definitions.xsd')
>>> xml = xml_from_file('/path/to/files/valid-example.xml')
>>> xsd.validate(xml)
True
>>> xml = xml_from_file('/path/to/files/invalid-example.xml')
>>> xsd.validate(xml)
False

The xml and xsd objects are lxml's lxml.etree._ElementTree and lxml.etree.XMLSchema objects respectively.

More information on the available API:

validate(xml, xsd)
    Receives an lxml.etree._ElementTree object as first parameter
    and an lxml.etree.XMLSchema object as second parameter and
    returns True or False respectively as the XSD validation of the
    XML succeeds or fails.

validate_from_files(xmlfilepath, xsdfilepath)
    Receives a string with a file path to a valid XML document 
    as first parameter and another string with a file path to a valid
    XSD document as second parameter and validates the first according 
    to the latter returning True or False respectively as the validation
    succeeds or fails.

validate_from_strings(xmlstr, xsdstr)
    Receives a string containing a valid XML document as first parameter
    and another string containing a valid XSD document as second parameter
    and validates the first according to the latter returning True or False
    respectively as the validation succeeds or fails.

validate_with_errors(xml, xsd)
    Returns a tuple with a boolean product of the XSD validation as
    the first element and the error log object as the second element.

validate_xml_string_from_xsd_file(xmlstr, xsdfilepath)
    Validates a string containing an XML document as the first parameter
    with an XSD document contained in the file path passed as the
    second parameter.

xml_from_file(filepath)
    Returns an lxml.etree._ElementTree object from a file
    containing a valid XML document.

xml_from_string(xmlstr)
    Returns an lxml.etree._ElementTree object from a string
    containing a valid XML document.

xsd_error_as_simple_string(error)
    Returns a string based on an XSD error object with the format
    LINE:COLUMN:LEVEL_NAME:DOMAIN_NAME:TYPE_NAME:MESSAGE.

xsd_error_log_as_simple_strings(error_log)
    Returns a list of strings representing all the errors of an XSD
    error log object.

Installation from Github

pip install https://github.com/gnrfan/python-easyxsd/zipball/master

Add this line to your requirements.txt file:

-e git+https://github.com/gnrfan/python-easyxsd.git@HEAD#egg=easyxsd

Then just run:

pip install -r requirements.txt.

(c) 2014 - Antonio Ognio [email protected]

python-easyxsd's People

Contributors

gnrfan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.