[Soap-Python] Returning an extensible array of key, value pairs from a SOAP service

burak.arslan at arskom.com.tr burak.arslan at arskom.com.tr
Thu Dec 2 12:12:47 CET 2010


 On Thu, 2 Dec 2010 08:01:16 +0100, "Dieter Maurer" 
 <dieter at handshake.de> wrote:
> Michael Wood wrote at 2010-12-1 14:05 +0200:
>> ...
>>>>> s = AnyAsDict()
>>>>> s.to_xml({"a": ["One"], "b": ["Two"], "c": [3]}, 'tns', parent)
>>>>> for element in parent.getchildren():
>>...     print etree.tostring(element)
>>...
>><ns0:retval xmlns:ns0="tns"><a>One</a><c>3</c><b>Two</b></ns0:retval>
>>>>> print s.from_xml(parent.getchildren()[0])
>>{'a': ['One'],'c': ['3'],'b': ['Two']}
>
> As you can see, you have lost type information: the integer "3"
> has been converted into the string "'3'".
>
> When types are important for your client sides, then this is likely
> not good enough.
>

 http://codespeak.net/lxml/objectify.html#python-data-types

>>> from lxml import objectify
>>> root = objectify.fromstring("<root><a>test</a><b>5</b></root>")
>>> root.a
 'test'
>>> root.a.pyval
 'test'
>>> root.b
 5
>>> root.b.text
 '5'
>>> root.b.pyval
 5

 look at doing it with a schema if you want to avoid guesswork.

 http://codespeak.net/lxml/objectify.html#asserting-a-schema

 hth
 burak


>
>
> --
> Dieter
> _______________________________________________
> Soap mailing list
> Soap at python.org
> http://mail.python.org/mailman/listinfo/soap




More information about the Soap mailing list