diff --git a/doc/components.rst b/doc/components.rst index 70e36c8e..182f98cf 100644 --- a/doc/components.rst +++ b/doc/components.rst @@ -88,24 +88,6 @@ Accessing a specific type of global component a dictionary access may be preferr .. doctest:: collection >>> schema.elements['person'] - XsdElement(name='person', occurs=[1, 1]) - >>> schema.types['personType'] - XsdComplexType(name='personType') - - The schema object has a dictionary attribute for each type of XSD declarations - ( - XsdElement(name='person', occurs=[1, 1]) - >>> schema.types['personType'] - XsdComplexType(name='personType') - - The schema object has a dictionary attribute for each type of XSD declarations - ( - XsdElement(name='person', occurs=[1, 1]) - >>> schema.types['personType'] - XsdComplexType(name='personType') - - The schema object has a dictionary attribute for each type of XSD declarations - ( XsdElement(name='person', occurs=[1, 1]) >>> schema.types['personType'] XsdComplexType(name='personType') @@ -126,98 +108,6 @@ loaded schemas in a structure called *maps*: .. doctest:: collection >>> person = schema.elements['person'] - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.xsd_elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.xsd_elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.xsd_elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.xsd_elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.xsd_elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.xsd_elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.xsd_elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) - >>> person - XsdElement(name='person', occurs=[1, 1]) - >>> schema.maps.xsd_elements[person.qualified_name] - XsdElement(name='person', occurs=[1, 1]) >>> person XsdElement(name='person', occurs=[1, 1]) >>> schema.maps.elements[person.qualified_name] @@ -261,18 +151,6 @@ XSD schema document: .. doctest:: collection >>> person = schema.elements['person'] - >>> person.schema - XMLSchema10(name='collection.xsd', namespace='http://example.com/ns/collection') - >>> person.elem - >> person.schema - XMLSchema10(name='collection.xsd', namespace='http://example.com/ns/collection') - >>> person.elem - >> person.schema - XMLSchema10(name='collection.xsd', namespace='http://example.com/ns/collection') - >>> person.elem - >> person.schema XMLSchema10(name='collection.xsd', namespace='http://example.com/ns/collection') >>> person.elem @@ -313,104 +191,6 @@ Every schema component includes methods for data conversion: .. doctest:: >>> schema = xmlschema.XMLSchema('tests/test_cases/examples/vehicles/vehicles.xsd') - >>> schema.types['vehicleType'].decode - - >>> schema.elements['cars'].encode - - - - Those methods can be used to decode the correspondents parts of the XML document: - >>> schema.types['vehicleType'].decode - - >>> schema.xsd_elements['cars'].encode - - - - Those methods can be used to decode the correspondents parts of the XML document: - >>> schema.types['vehicleType'].decode - - >>> schema.elements['cars'].encode - - - - Those methods can be used to decode the correspondents parts of the XML document: - >>> schema.types['vehicleType'].decode - - >>> schema.elements['cars'].encode - - - - Those methods can be used to decode the correspondents parts of the XML document: - >>> schema.types['vehicleType'].decode - - >>> schema.xsd_elements['cars'].encode - - - - Those methods can be used to decode the correspondents parts of the XML document: - >>> schema.types['vehicleType'].decode - - >>> schema.elements['cars'].encode - - - - Those methods can be used to decode the correspondents parts of the XML document: - >>> schema.types['vehicleType'].decode - - >>> schema.xsd_elements['cars'].encode - - - - Those methods can be used to decode the correspondents parts of the XML document: - >>> schema.types['vehicleType'].decode - - >>> schema.elements['cars'].encode - - - - Those methods can be used to decode the correspondents parts of the XML document: - >>> schema.types['vehicleType'].decode - - >>> schema.elements['cars'].encode - - - - Those methods can be used to decode the correspondents parts of the XML document: - >>> schema.types['vehicleType'].decode - - >>> schema.xsd_elements['cars'].encode - - - - Those methods can be used to decode the correspondents parts of the XML document: - >>> schema.types['vehicleType'].decode - - >>> schema.elements['cars'].encode - - - - Those methods can be used to decode the correspondents parts of the XML document: - >>> schema.types['vehicleType'].decode - - >>> schema.elements['cars'].encode - - - - Those methods can be used to decode the correspondents parts of the XML document: - >>> schema.types['vehicleType'].decode - - >>> schema.xsd_elements['cars'].encode - - - - Those methods can be used to decode the correspondents parts of the XML document: - >>> schema.types['vehicleType'].decode - - >>> schema.xsd_elements['cars'].encode - - - - Those methods can be used to decode the correspondents parts of the XML document: >>> schema.types['vehicleType'].decode >>> schema.elements['cars'].encode @@ -422,27 +202,6 @@ Those methods can be used to decode the correspondents parts of the XML document .. doctest:: >>> import xmlschema - >>> from pprint import pprint - >>> from xml.etree import ElementTree - >>> xs = xmlschema.XMLSchema('tests/test_cases/examples/vehicles/vehicles.xsd') - >>> xt = ElementTree.parse('tests/test_cases/examples/vehicles/vehicles.xml') - >>> root = xt.getroot() - >>> pprint(xs.elements['cars'].decode(root[0])) - {'{ - >>> from pprint import pprint - >>> from xml.etree import ElementTree - >>> xs = xmlschema.XMLSchema('tests/test_cases/examples/vehicles/vehicles.xsd') - >>> xt = ElementTree.parse('tests/test_cases/examples/vehicles/vehicles.xml') - >>> root = xt.getroot() - >>> pprint(xs.elements['cars'].decode(root[0])) - {'{ - >>> from pprint import pprint - >>> from xml.etree import ElementTree - >>> xs = xmlschema.XMLSchema('tests/test_cases/examples/vehicles/vehicles.xsd') - >>> xt = ElementTree.parse('tests/test_cases/examples/vehicles/vehicles.xml') - >>> root = xt.getroot() - >>> pprint(xs.xsd_elements['cars'].decode(root[0])) - {'{ >>> from pprint import pprint >>> from xml.etree import ElementTree >>> xs = xmlschema.XMLSchema('tests/test_cases/examples/vehicles/vehicles.xsd') @@ -450,314 +209,6 @@ Those methods can be used to decode the correspondents parts of the XML document >>> root = xt.getroot() >>> pprint(xs.elements['cars'].decode(root[0])) {'{http://example.com/vehicles}car': [{'@make': 'Porsche', '@model': '911'}, - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.xsd_elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.xsd_elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.xsd_elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.xsd_elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.xsd_elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.xsd_elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.xsd_elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.xsd_elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.xsd_elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.xsd_elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.xsd_elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.xsd_elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.xsd_elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.xsd_elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.xsd_elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.xsd_elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.xsd_elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.xsd_elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.xsd_elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.xsd_elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.xsd_elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.xsd_elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.xsd_elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.xsd_elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.xsd_elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.xsd_elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.xsd_elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} - {'@make': 'Porsche', '@model': '911'}]} - >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) - None - >>> pprint(xs.xsd_elements['bikes'].decode(root[1], namespaces={'vh': 'http://example.com/vehicles'})) - {'@xmlns:vh': 'http://example.com/vehicles', - 'vh:bike': [{'@make': 'Harley-Davidson', '@model': 'WL'}, - {'@make': 'Yamaha', '@model': 'XS650'}]} {'@make': 'Porsche', '@model': '911'}]} >>> pprint(xs.elements['cars'].decode(xt.getroot()[1], validation='skip')) None @@ -775,12 +226,6 @@ Every element or attribute declaration has a *type* attribute for accessing its .. doctest:: collection >>> person = schema.elements['person'] - >>> person.type - XsdComplexType(name='personType') - >>> person.type - XsdComplexType(name='personType') - >>> person.type - XsdComplexType(name='personType') >>> person.type XsdComplexType(name='personType') @@ -843,39 +288,6 @@ cases *content* is a not-empty `XsdGroup`: .. doctest:: collection >>> person = schema.elements['person'] - >>> person.type.has_complex_content() - True - >>> person.type.content - XsdGroup(model='sequence', occurs=[1, 1]) - >>> for item in person.type.content: - ... item - ... - XsdElement(name='name', occurs=[1, 1]) - XsdElement(name='born', occurs=[1, 1]) - XsdElement(name='dead', occurs=[0, 1]) - XsdElement(name='qualification', occurs=[0, 1]) - >>> person.type.has_complex_content() - True - >>> person.type.content - XsdGroup(model='sequence', occurs=[1, 1]) - >>> for item in person.type.content: - ... item - ... - XsdElement(name='name', occurs=[1, 1]) - XsdElement(name='born', occurs=[1, 1]) - XsdElement(name='dead', occurs=[0, 1]) - XsdElement(name='qualification', occurs=[0, 1]) - >>> person.type.has_complex_content() - True - >>> person.type.content - XsdGroup(model='sequence', occurs=[1, 1]) - >>> for item in person.type.content: - ... item - ... - XsdElement(name='name', occurs=[1, 1]) - XsdElement(name='born', occurs=[1, 1]) - XsdElement(name='dead', occurs=[0, 1]) - XsdElement(name='qualification', occurs=[0, 1]) >>> person.type.has_complex_content() True >>> person.type.content diff --git a/tests/test_cases/issues/issue_418/issue_418-invalid.xml b/tests/test_cases/issues/issue_418/issue_418-invalid.xml index 3f306050..fe2c8dcc 100644 --- a/tests/test_cases/issues/issue_418/issue_418-invalid.xml +++ b/tests/test_cases/issues/issue_418/issue_418-invalid.xml @@ -1,7 +1,7 @@ + xsi:noNamespaceSchemaLocation="issue_418.xsd" active="true"> diff --git a/tests/test_cases/issues/issue_418/issue_418-invalid2.xml b/tests/test_cases/issues/issue_418/issue_418-invalid2.xml deleted file mode 100644 index f311b1d1..00000000 --- a/tests/test_cases/issues/issue_418/issue_418-invalid2.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - diff --git a/tests/test_cases/issues/issue_418/issue_418.xml b/tests/test_cases/issues/issue_418/issue_418.xml index 536331fc..7a481a4c 100644 --- a/tests/test_cases/issues/issue_418/issue_418.xml +++ b/tests/test_cases/issues/issue_418/issue_418.xml @@ -1,7 +1,7 @@ + xsi:noNamespaceSchemaLocation="issue_418.xsd" active="true"> diff --git a/tests/validators/test_identities.py b/tests/validators/test_identities.py index 77c9bd4c..236cd9f3 100644 --- a/tests/validators/test_identities.py +++ b/tests/validators/test_identities.py @@ -127,22 +127,6 @@ def test_invalid_selector_path(self): self.assertIn("XPST0003", ctx.exception.message) - def test_selector_target_namespace(self): - schema = self.check_schema(""" - - - - - - - """) - - self.assertEqual(schema.identities['key1'].selector.target_namespace, - 'http://www.w3.org/2001/XMLSchema') - self.assertEqual(schema.identities['key1'].fields[0].target_namespace, '') - self.assertEqual(schema.identities['key1'].fields[1].target_namespace, - 'http://www.w3.org/2001/XMLSchema') - def test_invalid_selector_node(self): with self.assertRaises(XMLSchemaParseError) as ctx: self.check_schema(""" @@ -391,7 +375,6 @@ def test_keyref_counter(self): self.assertIn("value ('3',) not found", str(errors[1])) self.assertIn("(2 times)", str(errors[1])) - @unittest.skip def test_key_multiple_values__issue_418(self): xsd_file = self.casepath('issues/issue_418/issue_418.xsd') schema = self.schema_class(xsd_file) @@ -400,12 +383,9 @@ def test_key_multiple_values__issue_418(self): self.assertIsNone(schema.validate(xml_file)) xml_file = self.casepath('issues/issue_418/issue_418-invalid.xml') - with self.assertRaises(XMLSchemaValidationError): - schema.validate(xml_file) - - xml_file = self.casepath('issues/issue_418/issue_418-invalid2.xml') - with self.assertRaises(XMLSchemaValidationError): + with self.assertRaises(XMLSchemaValidationError) as ctx: schema.validate(xml_file) + self.assertIn("field selects multiple values", str(ctx.exception)) class TestXsd11Identities(TestXsdIdentities): diff --git a/xmlschema/validators/elements.py b/xmlschema/validators/elements.py index 4edccf16..fdfb08bd 100644 --- a/xmlschema/validators/elements.py +++ b/xmlschema/validators/elements.py @@ -15,7 +15,7 @@ from decimal import Decimal from types import GeneratorType from typing import TYPE_CHECKING, cast, Any, Dict, Iterator, List, Optional, \ - Set, Tuple, Type, Union, reveal_type + Set, Tuple, Type, Union from xml.etree.ElementTree import Element, ParseError from elementpath import XPath2Parser, ElementPathError, XPathContext, XPathToken, \ diff --git a/xmlschema/validators/identities.py b/xmlschema/validators/identities.py index e6b92b01..bd6d5adb 100644 --- a/xmlschema/validators/identities.py +++ b/xmlschema/validators/identities.py @@ -24,12 +24,13 @@ from ..names import XSD_UNIQUE, XSD_KEY, XSD_KEYREF, XSD_SELECTOR, XSD_FIELD from ..translation import gettext as _ from ..helpers import get_qname, get_extended_qname -from ..aliases import ElementType, SchemaType, NamespacesType, AtomicValueType, BaseXsdType +from ..aliases import ElementType, SchemaType, NamespacesType, AtomicValueType, \ + BaseXsdType, SchemaElementType, SchemaAttributeType from ..xpath import IdentityXPathParser, XPathElement from .exceptions import XMLSchemaNotBuiltError from .xsdbase import XsdComponent from .attributes import XsdAttribute -from .wildcards import XsdAnyElement +from .wildcards import XsdAnyElement, XsdWildcard from . import elements as elements_module if TYPE_CHECKING: @@ -40,6 +41,7 @@ IdentityMapType = Dict[Union['XsdKey', 'XsdKeyref', str, None], Union['IdentityCounter', 'KeyrefCounter']] IdentityNodeType = Union[ElementNode, AttributeNode] +FieldDecoderType = Union[SchemaElementType, SchemaAttributeType] class XsdSelector(XsdComponent): @@ -105,16 +107,6 @@ def __repr__(self) -> str: def built(self) -> bool: return True - @property - def target_namespace(self) -> str: - if self.token is None: - pass # xpathDefaultNamespace="##targetNamespace" - elif self.token.symbol == ':': - return self.token[1].namespace or self.xpath_default_namespace - elif self.token.symbol == '@' and self.token[0].symbol == ':': - return self.token[0][1].namespace or self.xpath_default_namespace - return self.schema.target_namespace - class XsdFieldSelector(XsdSelector): """Class for defining an XPath field selector for an XSD identity constraint.""" @@ -402,6 +394,8 @@ def iter_errors(self, identities: IdentityMapType) -> Iterator[XMLSchemaValueErr class FieldValueSelector: + skip_wildcard = False + def __init__(self, field: XsdFieldSelector, xsd_element: 'XsdElement') -> None: if field.token is None: msg = f"identity field {field} is not built" @@ -411,11 +405,6 @@ def __init__(self, field: XsdFieldSelector, xsd_element: 'XsdElement') -> None: self.xsd_element = xsd_element self.value_constraints = {} - if isinstance(field.parent, XsdKey): - self.admit_empty = False - else: - self.admit_empty = True - self.token = copy.deepcopy(field.token) schema_context = xsd_element.xpath_proxy.get_context() self.decoders = [] @@ -426,13 +415,17 @@ def __init__(self, field: XsdFieldSelector, xsd_element: 'XsdElement') -> None: "xs:field path must select only attributes and elements" ) - comp = cast(Union['XsdElement', XsdAttribute], node.value) + comp = cast(FieldDecoderType, node.value) self.decoders.append(comp) - value_constraint = comp.value_constraint - if value_constraint is not None: - self.value_constraints[node.name] = comp.type.text_decode(value_constraint) - if isinstance(comp, XsdAttribute): - self.value_constraints[None] = self.value_constraints[node.name] + if isinstance(comp, XsdWildcard): + if comp.process_contents == 'skip': + self.skip_wildcard = True + else: + value_constraint = comp.value_constraint + if value_constraint is not None: + self.value_constraints[node.name] = comp.type.text_decode(value_constraint) + if isinstance(comp, XsdAttribute): + self.value_constraints[None] = self.value_constraints[node.name] if len(self.decoders) > 1 and None in self.value_constraints: self.value_constraints.pop(None) @@ -450,7 +443,6 @@ def get_value(self, element_node: ElementNode, empty = True for node in cast(Iterator[IdentityNodeType], self.token.select(context)): - if empty: empty = False else: @@ -464,7 +456,10 @@ def get_value(self, element_node: ElementNode, raise XMLSchemaTypeError(msg % (self.field, type(node))) if xsd_type is None: - value = node.string_value + if self.skip_wildcard: + value = None + else: + value = node.string_value elif xsd_type.content_type_label not in ('simple', 'mixed'): msg = _("%r field doesn't have a simple type!") raise XMLSchemaTypeError(msg % self.field) @@ -478,9 +473,10 @@ def get_value(self, element_node: ElementNode, value = node.typed_value # type: ignore[assignment,unused-ignore] except (KeyError, ValueError): for decoder in self.decoders: - if node.match_name(decoder.name): - value = decoder.type.text_decode(node.string_value) - break + if not isinstance(decoder, XsdWildcard): + if decoder.is_matching(node.name): + value = decoder.type.text_decode(node.string_value) + break else: value = node.string_value