@@ -0,0 +1,3116 @@
+#!/usr/bin/env python%0A# encoding: utf8%0A#%0A# Copyright %C2%A9 Burak Arslan %3Cburak at arskom dot com dot tr%3E,%0A#             Arskom Ltd. http://www.arskom.com.tr%0A# All rights reserved.%0A#%0A# Redistribution and use in source and binary forms, with or without%0A# modification, are permitted provided that the following conditions are met:%0A#%0A#    1. Redistributions of source code must retain the above copyright notice,%0A#       this list of conditions and the following disclaimer.%0A#    2. Redistributions in binary form must reproduce the above copyright%0A#       notice, this list of conditions and the following disclaimer in the%0A#       documentation and/or other materials provided with the distribution.%0A#    3. Neither the name of the owner nor the names of its contributors may be%0A#       used to endorse or promote products derived from this software without%0A#       specific prior written permission.%0A#%0A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS %22AS IS%22%0A# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE%0A# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE%0A# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,%0A# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,%0A# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,%0A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY%0A# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING%0A# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,%0A# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.%0A#%0A%0Afrom lxml import etree%0A%0Afrom spyne.model import Unicode%0Afrom spyne.model import Integer%0Afrom spyne.model import ComplexModel%0Afrom spyne.interface.xml_schema.parser import own_repr%0A%0Afrom spyne.util.xml import get_schema_documents%0Afrom spyne.util.xml import get_object_as_xml%0Afrom spyne.util.xml import get_xml_as_object%0Afrom spyne.util.xml import parse_schema_string%0A%0A# Define the object%0Aclass SomeObject(ComplexModel):%0A    i = Integer%0A    s = Unicode%0A    __repr__ = own_repr%0A%0A# Instantiate the object%0Ainstance = SomeObject(i=5, s=%22str%22)%0A%0A# Generate the xml schema for object%0Aschema = etree.tostring(get_schema_documents(%5BSomeObject%5D, 'some_ns')%5B'tns'%5D,%0A                                                              pretty_print=True)%0A# Serialize the object to XML%0Adata = etree.tostring(get_object_as_xml(instance, SomeObject),%0A                                                              pretty_print=True)%0A%0Aprint instance%0Aprint%0Aprint schema%0Aprint data%0A%0A# parse the schema document%0Aparsed_schema = parse_schema_string(schema)%5B'some_ns'%5D%0A%0A# Get SomeObject definition from the parsed schema document%0ANewObject = parsed_schema.types%5B'SomeObject'%5D%0A%0A# We print an empty instance just to see the parsed fields.%0Aprint NewObject()%0A%0A# Deserialize the xml document using the definition from the schema.%0Anew_instance = get_xml_as_object(etree.fromstring(data), NewObject)%0A%0Aprint new_instance%0A%0Aassert new_instance.s == instance.s%0Aassert new_instance.i == instance.i%0A

add xml schema parsing example