Open GoogleCodeExporter opened 9 years ago
Handling attributes is a known issue, but how should we map them to python
types?
What do you suggest?
BTW, you can use the raw client.xml_response and parse it with SimpleXMLElement
and then access the tag/attributes directly:
xml = SimpleXMLElement(client.xml_response)
print xml('tag')['attribute']
https://code.google.com/p/pysimplesoap/wiki/SimpleXmlElement
For testing, can you attach a sample wsld, xml_request and xml_response?
Original comment by reingart@gmail.com
on 23 Sep 2013 at 1:42
I'm having the same issue right now -- missing xml attributes.
What about to map attributes to a python list of dicts in this way:
{ 'tag': [ {'first_attribute': first_attribute_value}, {'second_attribute':
'second_attribute_value} ...] ...}
Ok, this is only my 0.5 eurocents on this topic...
Thanks,
Simone
Original comment by simone.fabris
on 24 Sep 2013 at 4:40
I'm no longer using WSDL but trying to provide help for this issue.
The WSDL I use is from http://marsorange.com/files/zimbra_admin-example.wsdl
http://files.zimbra.com/docs/soap_api/8.0.4/soap-docs-804/api-reference/zimbraAd
min/GetAllDomains.html
Sample request is :
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
<context xmlns="urn:zimbra">
<authToken xsi:type="xsd:string">0_e65a1STRIPPED6272613b
</authToken>
<sessionId xsi:null="1"/>
</context>
</soap:Header>
<soap:Body>
<GetAllDomainsRequest xmlns="urn:zimbraAdmin">
</GetAllDomainsRequest>
</soap:Body>
</soap:Envelope>
and sample response is :
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<context xmlns="urn:zimbra">
<change token="STRIPPED"/>
</context>
</soap:Header>
<soap:Body>
<GetAllDomainsResponse xmlns="urn:zimbraAdmin">
<domain id="b37dSTRIPPEDecf6ac" name="client1.unbound.example.net">
<a n="zimbraGalLdapPageSize">1000</a>
<a n="zimbraAggregateQuotaLastUsage">401</a>
<a n="zimbraInternalSharingCrossDomainEnabled">TRUE</a>
<a n="zimbraMailStatus">enabled</a>
<a n="zimbraGalSyncTimestampFormat">yyyyMMddHHmmss'Z'</a>
<a n="zimbraGalSyncLdapPageSize">1000</a>
<a n="zimbraZimletDataSensitiveInMixedModeDisabled">TRUE</a>
<a n="zimbraId">b37dSTRIPPEDecf6ac
</domain>
</GetAllDomainsResponse>
</soap:Body>
</soap:Envelope>
So the main information here (domain name) is contained within attribute "name"
from element "<domain/>" (zimbra API is not very close to SOAP philosophy but
that's another story…).
btw, about Simone proposal :
What about to map attributes to a python list of dicts in this way:
{ 'tag': [ {'first_attribute': first_attribute_value}, {'second_attribute': 'second_attribute_value} ...] ...}
This proposal does not adresses the main question : how you access the nested
levels of tags attributes ? However, it adresses the question of final
representation (how to store the attributes of a single node).
However, XML attributes can only occur once per-tag, and
[http://www.w3.org/TR/REC-xml/#sec-starttags their order has no importance]. So
a dict is enough to store the attributes of a single node. list of dicts is
overkill.
Regarding the structure ; currently, iirc, each node is a python dict ; why
not extending python dict class overloading __getattr__ to access the
attributes of a node ? What do you think about it ?
Original comment by joce...@crapouillou.net
on 30 Sep 2013 at 9:39
Original issue reported on code.google.com by
joce...@crapouillou.net
on 23 Sep 2013 at 7:34