[spyne] Serializing a model

Burak Arslan burak.arslan at arskom.com.tr
Thu Jun 19 15:44:03 UTC 2014


On 06/19/14 17:30, Joseph L. Casale wrote:
>> class Node(ComplexModel):
>>     ATTR = XmlAttribute(Unicode)
>>     data = XmlData(Unicode(max_len=450, values=['1st', '2nd']))
>>
>>
>> class Foo(ComplexModel):
>>     node_a = Node.customize(max_occurs=2)
>>    node_b = Unicode(max_len=450)
> What I get is a wsdl like this:
>
>   <urn1:Node ATTR="?">
>     <spy:data/>
>   </urn1:Node>
>
> Whereas the element must not be nested:
>
> <Node ATTR="1st">foo</Node>
>
> Thats why I reverted to using attribute_of knowing it was on its way out.
>

huh. this is supposed to work, the sole purpose of XmlData is to have
whatever's inside as simpleContent.

See: https://gist.github.com/plq/11e4c28d5eeba7d145a7

Could you please modify this to produce the above document and let me know?

Best regards,
Burak

For completeness:

from spyne import *
from spyne.util.xml import get_object_as_xml
from lxml import etree

class Node(ComplexModel):
    ATTR = XmlAttribute(Unicode)
    data = XmlData(Unicode(max_len=450, values=['1st', '2nd']))


class Foo(ComplexModel):
    node_a = Node.customize(max_occurs=2)
    node_b = Unicode(max_len=450)

elt = get_object_as_xml(
  Foo(
    node_a=[
      Node('data1', ATTR='1st'),
      Node('data2', ATTR='2nd'),
    ],
    node_b="more_data",
  ), 
  Foo
)

print(etree.tostring(elt, pretty_print=True))






More information about the people mailing list