XML - Managing Data Exchange/XMLRPC - Serializing/Deserializing DataTypes

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

[edit] XMLRPC - Serializing and Deserializing Datatypes

As a lightweight alternative to SOAP, Dave Winer came up with XMLRPC as a means to make remote method calls and exchange data between servers. The spec for this format is located at http://www.xmlrpc.com/spec.

It works well for its intended use. Well, unless you are coding in PHP and using the built-in, undocumented functions to generate XMLRPC. You may have to build your own, just to be on the safe side.

Just a quick example of what it looks like. In xmlrpc, a <struct> is what we would call in php an 'associative array', whereas an <array> is a 'list' or an array with only numerical indices (or in some languages, no indices). A complex array datatype with the following structure:

Array
(
	[0] => dogs
	[1] => cats
	[animals] => Array(
		[0] => FALSE
		[1] => little_dogs
		[2] => little_cats
		[3] => 5
		[4] => 2.3
		[5] => 1
			),
)

Becomes the following XMLRPC:

<?xml version="1.0" encoding="utf-8"?>
<methodResponse>
      <params>
         <param>
            <value>
               <struct>
                  <member>
                     <name>0
                     </name>
                     <value><string>dogs</string>
                     </value>
                  </member>
                  <member>
                     <name>1
                     </name>
                     <value><string>cats</string>
                     </value>
                  </member>
                  <member>
                     <name>animals
                     </name>
                     <value>
                           <array>
                              <data>
                                 <value><boolean>0</boolean>
                                 </value>
                                 <value><string>little_dogs</string>
                                 </value>
                                 <value><string>little_cats</string>
                                 </value>
                                 <value><i4>5</i4>
                                 </value>
                                 <value><double>2.3</double>
                                 </value>
                                 <value><boolean>1</boolean>
                                 </value>
                              </data>
                           </array>
                     </value>
                  </member>
               </struct>
            </value>
         </param>
      </params>
</methodResponse>