We have been using the kSOAP2 library for SOAP communications on Android. Previously, we discussed using Manfred Moser’s fork which fixed the a bug with SoapObject#getAttribute
, and adding methods to check whether a particular property or attribute exists.
Last week, we ran into another limitation: kSOAP2 doesn’t attach attributes to primitives. For example, when parsing the response below, kSOAP2 ignores the grade
attribute on the <person>
elements.
This limitation is not necessarily a bug (for reasons explained later); but, our current project requires us to parse SOAP responses with such a structure.
To parse these SOAP responses, we added attributes to the SoapPrimitive
class. Specifically, we moved the attribute-related code from SoapObject
into a base class called AttributeContainer
, then had SoapPrimitive
extend SoapObject
. Thus, users can now retrieve attributes from a SoapPrimitive
the same way they would retrieve them from a SoapObject
:
kSOAP2’s ignoring of attributes on primitive elements may be a design decision rather than a bug. The kSOAP2 tests emphasize the use of the KvmSerializable
interface. This interface is intended to be used to parse SOAP responses in which the elements are typed. When an element containing text is typed, the parser does not create a corresponding SoapPrimitive
object. Instead it converts that element into the appropriate object and places that object into the parent SoapObject
. Thus, there is no place to place this element’s attributes.
For example in the XML below
kSOAP2 places the string “This is a string
” directly in the SoapObject
corresponding to <ComplexFunctionReturn>
.
This emphasis on typing and serialization does not affect the design of our application; but, users of our kSOAP2 updates should take care when using our features together with strongly typed SOAP responses.
Resources
- Discussion of Matt Fletcher’s previous changes
- Manfred Moser’s fork
- kSOAP2