.. _package-api:

***********
Package API
***********


.. _errors-and-exceptions:

Errors and exceptions
=====================

.. autoexception:: xmlschema.XMLSchemaException
.. autoexception:: xmlschema.XMLSchemaResourceError
.. autoexception:: xmlschema.XMLSchemaRegexError
.. autoexception:: xmlschema.XMLSchemaNamespaceError

.. autoexception:: xmlschema.XMLSchemaValidatorError
.. autoexception:: xmlschema.XMLSchemaNotBuiltError
.. autoexception:: xmlschema.XMLSchemaParseError
.. autoexception:: xmlschema.XMLSchemaModelError
.. autoexception:: xmlschema.XMLSchemaModelDepthError
.. autoexception:: xmlschema.XMLSchemaValidationError
.. autoexception:: xmlschema.XMLSchemaDecodeError
.. autoexception:: xmlschema.XMLSchemaEncodeError
.. autoexception:: xmlschema.XMLSchemaChildrenValidationError

.. autoexception:: xmlschema.XMLSchemaIncludeWarning
.. autoexception:: xmlschema.XMLSchemaImportWarning
.. autoexception:: xmlschema.XMLSchemaTypeTableWarning


.. _document-level-api:

Document level API
==================

.. autofunction:: xmlschema.validate
.. autofunction:: xmlschema.is_valid
.. autofunction:: xmlschema.iter_errors
.. autofunction:: xmlschema.to_dict
.. autofunction:: xmlschema.to_json
.. autofunction:: xmlschema.from_json


.. _schema-level-api:

Schema level API
================

.. class:: xmlschema.XMLSchema10
.. class:: xmlschema.XMLSchema11

    The classes for XSD v1.0 and v1.1 schema instances. They are both generated by the
    meta-class :class:`XMLSchemaMeta` and take the same API of :class:`XMLSchemaBase`.

.. autoclass:: xmlschema.XMLSchema

.. autoclass:: xmlschema.XMLSchemaBase

    .. autoattribute:: root
    .. automethod:: get_text
    .. autoattribute:: url

    .. autoattribute:: tag
    .. autoattribute:: id
    .. autoattribute:: version

    .. autoattribute:: schema_location
    .. autoattribute:: no_namespace_schema_location
    .. autoattribute:: target_prefix
    .. autoattribute:: default_namespace
    .. autoattribute:: base_url
    .. autoattribute:: root_elements
    .. autoattribute:: simple_types
    .. autoattribute:: complex_types

    .. automethod:: builtin_types
    .. automethod:: create_meta_schema
    .. automethod:: create_any_content_group
    .. automethod:: create_any_attribute_group
    .. automethod:: create_any_type

    .. automethod:: get_locations
    .. automethod:: include_schema
    .. automethod:: import_schema
    .. automethod:: export
    .. automethod:: resolve_qname
    .. automethod:: iter_globals
    .. automethod:: iter_components

    .. automethod:: check_schema
    .. automethod:: build
    .. automethod:: clear
    .. autoattribute:: built
    .. autoattribute:: validation_attempted
    .. autoattribute:: validity
    .. autoattribute:: all_errors

    .. automethod:: get_converter
    .. automethod:: validate
    .. automethod:: is_valid
    .. automethod:: iter_errors
    .. automethod:: decode

    .. _schema-iter_decode:

    .. automethod:: iter_decode
    .. automethod:: encode

    .. _schema-iter_encode:

    .. automethod:: iter_encode


.. _global-maps-api:

Global maps API
===============

.. autoclass:: xmlschema.XsdGlobals
    :members: copy, register, iter_schemas, iter_globals, lookup_notation, lookup_type,
        lookup_attribute, lookup_attribute_group, lookup_group, lookup_element, lookup,
        clear, build, unbuilt, check


.. _converters-api:

Converters API
==============

The base class `XMLSchemaConverter` is used for defining generic converters.
The subclasses implement some of the most used `conventions for converting XML
to JSON data <http://wiki.open311.org/JSON_and_XML_Conversion/>`_.

.. autoclass:: xmlschema.converters.ElementData

.. autoclass:: xmlschema.XMLSchemaConverter

    .. autoattribute:: lossy
    .. autoattribute:: losslessly

    .. automethod:: copy
    .. automethod:: map_attributes
    .. automethod:: map_content
    .. automethod:: etree_element
    .. automethod:: element_decode
    .. automethod:: element_encode

    .. automethod:: map_qname
    .. automethod:: unmap_qname

.. autoclass:: xmlschema.UnorderedConverter

.. autoclass:: xmlschema.ParkerConverter

.. autoclass:: xmlschema.BadgerFishConverter

.. autoclass:: xmlschema.AbderaConverter

.. autoclass:: xmlschema.JsonMLConverter

.. autoclass:: xmlschema.ColumnarConverter


.. _xml-resource-api:

XML resource API
================

.. autoclass:: xmlschema.XMLResource

    .. autoattribute:: root
    .. autoattribute:: document
    .. autoattribute:: text
    .. autoattribute:: url
    .. autoattribute:: base_url
    .. autoattribute:: namespace

    .. automethod:: copy
    .. automethod:: tostring
    .. automethod:: open
    .. automethod:: load
    .. automethod:: is_lazy
    .. autoattribute:: lazy_depth
    .. automethod:: is_remote
    .. automethod:: is_local
    .. automethod:: is_loaded
    .. automethod:: iter
    .. automethod:: iter_subtrees
    .. automethod:: iter_location_hints
    .. automethod:: get_namespaces
    .. automethod:: get_locations

    .. automethod:: defusing
    .. automethod:: parse
    .. automethod:: iterparse
    .. automethod:: fromstring


.. autofunction:: xmlschema.fetch_resource
.. autofunction:: xmlschema.fetch_schema
.. autofunction:: xmlschema.fetch_schema_locations
.. autofunction:: xmlschema.normalize_url


.. _xpath-api:

XPath API
=========

Implemented through a mixin class on XSD schemas and elements.

.. autoclass:: xmlschema.ElementPathMixin

    .. autoattribute:: tag
    .. autoattribute:: attrib
    .. automethod:: get
    .. automethod:: iter
    .. automethod:: iterchildren
    .. automethod:: find
    .. automethod:: findall
    .. automethod:: iterfind


.. _validation-api:

Validation API
==============

Implemented for XSD schemas, elements, attributes, types, attribute
groups and model groups.

.. autoclass:: xmlschema.validators.ValidationMixin

    .. automethod:: is_valid
    .. automethod:: validate
    .. automethod:: decode
    .. automethod:: iter_decode
    .. automethod:: iter_encode
        :noindex:
    .. automethod:: iter_errors
    .. automethod:: encode
    .. automethod:: iter_encode


.. _particles-api:

Particles API
=============

Implemented for XSD model groups, elements and element wildcards.

.. autoclass:: xmlschema.validators.ParticleMixin

    .. automethod:: is_empty
    .. automethod:: is_emptiable
    .. automethod:: is_single
    .. automethod:: is_multiple
    .. automethod:: is_ambiguous
    .. automethod:: is_univocal
    .. automethod:: is_missing
    .. automethod:: is_over


.. _main-xsd-components:

Main XSD components
===================

.. autoclass:: xmlschema.XsdComponent

    .. autoattribute:: target_namespace
    .. autoattribute:: local_name
    .. autoattribute:: qualified_name
    .. autoattribute:: prefixed_name
    .. automethod:: is_global
    .. automethod:: is_matching
    .. automethod:: tostring

.. autoclass:: xmlschema.XsdType
    :members: is_simple, is_complex, is_atomic, is_list, is_datetime, is_empty,
        is_emptiable, has_simple_content, has_complex_content, has_mixed_content,
        is_element_only, is_derived, is_extension, is_restriction, is_key, is_qname

    .. autoattribute:: simple_type
    .. autoattribute:: model_group

.. autoclass:: xmlschema.XsdElement
.. autoclass:: xmlschema.XsdAttribute


.. _other-xsd-components:

Other XSD components
====================

Elements and attributes
-----------------------
.. autoclass:: xmlschema.validators.Xsd11Element
.. autoclass:: xmlschema.validators.Xsd11Attribute


Types
-----
.. autoclass:: xmlschema.validators.Xsd11ComplexType
.. autoclass:: xmlschema.validators.XsdComplexType

    .. autoattribute:: content_type

.. autoclass:: xmlschema.validators.XsdSimpleType

    .. autoattribute:: enumeration
    .. autoattribute:: max_value
    .. autoattribute:: min_value

.. autoclass:: xmlschema.validators.XsdAtomicBuiltin
.. autoclass:: xmlschema.validators.XsdList
.. autoclass:: xmlschema.validators.Xsd11Union
.. autoclass:: xmlschema.validators.XsdUnion
.. autoclass:: xmlschema.validators.Xsd11AtomicRestriction
.. autoclass:: xmlschema.validators.XsdAtomicRestriction


Attribute and model groups
--------------------------
.. autoclass:: xmlschema.validators.XsdAttributeGroup
.. autoclass:: xmlschema.validators.Xsd11Group
.. autoclass:: xmlschema.validators.XsdGroup


Wildcards
---------
.. autoclass:: xmlschema.validators.Xsd11AnyElement
.. autoclass:: xmlschema.validators.XsdAnyElement
.. autoclass:: xmlschema.validators.Xsd11AnyAttribute
.. autoclass:: xmlschema.validators.XsdAnyAttribute
.. autoclass:: xmlschema.validators.XsdOpenContent
.. autoclass:: xmlschema.validators.XsdDefaultOpenContent


Identity constraints
--------------------
.. autoclass:: xmlschema.validators.XsdIdentity
.. autoclass:: xmlschema.validators.XsdSelector
.. autoclass:: xmlschema.validators.XsdFieldSelector
.. autoclass:: xmlschema.validators.Xsd11Unique
.. autoclass:: xmlschema.validators.XsdUnique
.. autoclass:: xmlschema.validators.Xsd11Key
.. autoclass:: xmlschema.validators.XsdKey
.. autoclass:: xmlschema.validators.Xsd11Keyref
.. autoclass:: xmlschema.validators.XsdKeyref


Facets
------
.. autoclass:: xmlschema.validators.XsdFacet
.. autoclass:: xmlschema.validators.XsdWhiteSpaceFacet
.. autoclass:: xmlschema.validators.XsdLengthFacet
.. autoclass:: xmlschema.validators.XsdMinLengthFacet
.. autoclass:: xmlschema.validators.XsdMaxLengthFacet
.. autoclass:: xmlschema.validators.XsdMinInclusiveFacet
.. autoclass:: xmlschema.validators.XsdMinExclusiveFacet
.. autoclass:: xmlschema.validators.XsdMaxInclusiveFacet
.. autoclass:: xmlschema.validators.XsdMaxExclusiveFacet
.. autoclass:: xmlschema.validators.XsdTotalDigitsFacet
.. autoclass:: xmlschema.validators.XsdFractionDigitsFacet
.. autoclass:: xmlschema.validators.XsdExplicitTimezoneFacet
.. autoclass:: xmlschema.validators.XsdAssertionFacet
.. autoclass:: xmlschema.validators.XsdEnumerationFacets
.. autoclass:: xmlschema.validators.XsdPatternFacets


Others
------
.. autoclass:: xmlschema.validators.XsdAssert
.. autoclass:: xmlschema.validators.XsdAlternative
.. autoclass:: xmlschema.validators.XsdNotation
.. autoclass:: xmlschema.validators.XsdAnnotation
