Skip to content

Instantly share code, notes, and snippets.

@plq
Created June 19, 2014 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plq/11e4c28d5eeba7d145a7 to your computer and use it in GitHub Desktop.
Save plq/11e4c28d5eeba7d145a7 to your computer and use it in GitHub Desktop.
<Foo>
<node_b>more_data</node_b>
<node_a ATTR="1st">data1</node_a>
<node_a ATTR="2nd">data2</node_a>
</Foo>
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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment