예제 #1
0
    def test_simple_content(self):
        tns = 'some_ns'

        schema = """<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="some_ns"
            elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xsd:complexType name="SomeGuy">
        <xsd:simpleContent>
            <xsd:extension base="xsd:string">
                <xsd:attribute name="attr" type="xsd:string" use="optional"/>
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>
</xsd:schema>"""

        objects = parse_schema_string(schema)
        pprint(objects[tns].types)

        NewGuy = objects[tns].types['SomeGuy']
        ti = NewGuy._type_info
        pprint(dict(ti))
        assert issubclass(ti['_data'], XmlData)
        assert ti['_data'].type is Unicode

        assert issubclass(ti['attr'], XmlAttribute)
        assert ti['attr'].type is Unicode
예제 #2
0
# Serialize the xml schema document for object
schema = etree.tostring(schema_elts['tns'], pretty_print=True)

# Serialize the object to XML
instance_elt = get_object_as_xml(instance, SomeObject)

# Serialize the element tree to string
data = etree.tostring(instance_elt, pretty_print=True)

print instance
print
print schema
print data

# parse the schema document
parsed_schema = parse_schema_string(schema)['some_ns']

# Get SomeObject definition from the parsed schema document
NewObject = parsed_schema.types['SomeObject']

# We print an empty instance just to see the parsed fields.
print NewObject()

# Deserialize the xml document using the definition from the schema.
new_instance = get_xml_as_object(etree.fromstring(data), NewObject)

print new_instance

assert new_instance.s == instance.s
assert new_instance.i == instance.i
assert new_instance.d == instance.d
예제 #3
0
파일: schema.py 프로젝트: 1-bit/spyne
# Serialize the xml schema document for object
schema = etree.tostring(schema_elts['tns'],  pretty_print=True)

# Serialize the object to XML
instance_elt = get_object_as_xml(instance, SomeObject)

# Serialize the element tree to string
data = etree.tostring(instance_elt, pretty_print=True)

print(instance)
print()
print(schema)
print(data)

# parse the schema document
parsed_schema = parse_schema_string(schema)['some_ns']

# Get SomeObject definition from the parsed schema document
NewObject = parsed_schema.types['SomeObject']

# We print an empty instance just to see the parsed fields.
print(NewObject())

# Deserialize the xml document using the definition from the schema.
new_instance = get_xml_as_object(etree.fromstring(data), NewObject)

print(new_instance)

assert new_instance.s == instance.s
assert new_instance.i == instance.i
assert new_instance.d == instance.d
예제 #4
0
# Serialize the xml schema document for object
schema = etree.tostring(schema_elts["tns"], pretty_print=True)

# Serialize the object to XML
instance_elt = get_object_as_xml(instance, SomeObject)

# Serialize the element tree to string
data = etree.tostring(instance_elt, pretty_print=True)

print instance
print
print schema
print data

# parse the schema document
parsed_schema = parse_schema_string(schema)["some_ns"]

# Get SomeObject definition from the parsed schema document
NewObject = parsed_schema.types["SomeObject"]

# We print an empty instance just to see the parsed fields.
print NewObject()

# Deserialize the xml document using the definition from the schema.
new_instance = get_xml_as_object(etree.fromstring(data), NewObject)

print new_instance

assert new_instance.s == instance.s
assert new_instance.i == instance.i
assert new_instance.d == instance.d