Representing objects
Let's create an object, then serialize it using two different approaches. Some contrasts will come to the fore:
Listing 2. Python shell example of XML-RPC serialization
|
You should note a few things already. First, the whole XML document has a root <methodCall>
element which is irrelevant to our current purposes. Other than a few
bytes extra, however, the additional enclosing element is unimportant.
Likewise, the <methodName>
is superfluous, but the example gives a name that indicates the role of the document. Moreover, a call to xmlrpclib.dumps()
accepts a tuple of objects, but we are only interested in "pickling" one (if there were others, they would have their own <param>
element). But other than some wrapping, the attributes of our object are well-contained within the <struct>
element's <member>
elements.
Now let's look at what xml_pickle
does (the object is the same as above):
|
There is both less and more to the xml_pickle
version (the actual sizes of both are comparable). Notice that even
though Python does not have a built-in Boolean type, when you use a
class to represent a new type, xml_pickle
adjusts readily
(albeit more verbosely). XML-RPC, by contrast, is limited to
serializing its eight data types, and nothing else. Of course, two of
those types,<array>
and <struct>
, are themselves collections and can be compound. In addition, xml_pickle
can point multiple collection members to the same underlying object;
this is absent by design from XML-RPC (and introduced in later versions
of xml_pickle
also). As a small matter, xml_pickle
contains only a single numeric
type attribute, but the actual pattern of the value
attribute allows for decoding to integer, float, complex, and so on. No
real generality is lost or gained by these strategies, although the
XML-RPC style will appeal aesthetically to programmers working with
statically typed languages.
View XML-RPC as object model Discussion
Page: 1 2 3 4 5 6 Next Page: Weaknesses of XML-RPC