Example #1
0
    def test_any_tag(self):
        logging.basicConfig(level=logging.DEBUG)

        class SomeType(ComplexModel):
            __namespace__ = "zo"

            anything = AnyXml(schema_tag='{%s}any' % ns.xsd, namespace='##other',
                                                         process_contents='lax')

        from lxml import etree

        #import ipdb; ipdb.set_trace()

        docs = get_schema_documents([SomeType])
        print etree.tostring(docs['tns'], pretty_print=True)
        any = docs['tns'].xpath('//xsd:any', namespaces={'xsd': ns.xsd})

        assert len(any) == 1
        assert any[0].attrib['namespace'] == '##other'
        assert any[0].attrib['processContents'] == 'lax'
Example #2
0
    b = Integer
    c = Decimal
    d = DateTime


class Foo(ComplexModel):
    __namespace__ = "some_other_namespace"

    a = String
    b = Integer
    c = Decimal
    d = DateTime
    e = XmlAttribute(Integer)


docs = get_schema_documents([Punk, Foo])
pprint(docs)
print()

# the default ns prefix is always tns
print("the default namespace %r:" % docs["tns"].attrib["targetNamespace"])
print(etree.tostring(docs["tns"], pretty_print=True))
print()

# Namespace prefixes are assigned like s0, s1, s2, etc...
print("the other namespace %r:" % docs["s0"].attrib["targetNamespace"])
print(etree.tostring(docs["s0"], pretty_print=True))


foo = Foo(a="a", b=1, c=3.4, d=datetime(2011, 02, 20), e=5)
doc = get_object_as_xml(foo)
Example #3
0
    a = String
    b = Integer
    c = Decimal
    d = DateTime


class Foo(ComplexModel):
    __namespace__ = 'some_other_namespace'

    a = String
    b = Integer
    c = Decimal
    d = DateTime


docs = get_schema_documents([Punk, Foo])
pprint(docs)
print()

# the default ns prefix is always tns
print("the default namespace %r:" % docs['tns'].attrib['targetNamespace'])
print(etree.tostring(docs['tns'], pretty_print=True))
print()

# Namespace prefixes are assigned like s0, s1, s2, etc...
print("the other namespace %r:" % docs['s0'].attrib['targetNamespace'])
print(etree.tostring(docs['s0'], pretty_print=True))

foo = Foo(a='a', b=1, c=3.4, d=datetime(2011, 02, 20))
print(etree.tostring(get_object_as_xml(foo), pretty_print=True))