Anne Thomas Manes wrote:

... In order to pass a
key/value pair, you need to define an XML Schema structure that can convey
the key/value pair information. And that structure should be defined as an
array.

It's actually pretty hard to describe your first XML representation of the
map instance in XML Schema:

<map>
<key>321</key>
<value>Adam</value>
<key>492</key>
<value>Becky</value>
<map>


It's actually easy to represent this in schema, as:

 <complexType name="map">
   <sequence>
     <complexType minOccurs="0" maxOccurs="unbounded">
       <sequence>
         <element name="key" type="xsd:string"/>
         <element name="value" type="xsd:string"/>
       </sequence>
     </complexType>
   </sequence>
 </complexType>

For some reason people in the web services world seem to avoid nesting complex type, but they're a common feature of schemas. Any component that has minOccurs="0" and maxOccurs="unbounded" is the equivalent of an array in programming language terms.

You don't have an array in here, so you really can't represent the repeating
structure information, unless you want to use <xsd:any> in the definition.


It's a much better idea to define the structure as an array:

<element name="map">
<complexType>
<sequence>
<element name="item" type="tns:item" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
<complexType name="item">
<sequence>
<element name="key" type="string"/>
<element name="value" type="string"/>
</sequence>
</complexType>


But this schema would produce a document structure like this:

<map>
 <item>
   <key>321</key>
   <value>Adam</value>
 </item>
 <item>
   <key>492</key>
   <value>Becky</value>
 </item>
<map>

Now it's up to your serialization framework to map the array to a Java
collection.

I reiterate -- as a developer, your should define your SOAP interface based
on the XML structures you wish to exchange, not based on your Java service
object model.


Yes, I think we're in vehement agreement on that!

 - Dennis

Anne

-----Original Message-----
From: Dennis Sosnoski [mailto:[EMAIL PROTECTED] Sent: Tuesday, November 02, 2004 3:34 AM
To: [EMAIL PROTECTED]
Subject: Re: Maximum Interoperability with "Map" objects


Anne, I think you're conflating the programming model and the data model here. I know you're doing it in the interest of keeping things simple, but I'm not sure that's a good idea in this case.

XML Schema can describe many representations of hashmaps, such as:

 <map>
   <key>321</key>
   <value>Adam</value>
   <key>492</key>
   <value>Becky</value>
  <map>
or

<map>
<item key="321"><person><first-name>Adam</first-name><last-name>Smith</last-name><
address>...</person></item>
<item key="492"><person><first-name>Becky</first-name>...</person></item>
</map>


There's just no one representation that's standard for hashmaps across languages and SOAP platforms. But the whole point of the move to doc/lit is that people need to describe the data they want to exchange in their web services, not the actual program implementations used for handling that data. If you've got a need to use data in the form of key-value pairs in your web service go ahead and do so, but recognize that depending on the framework you use you may need to go through some translation to take this to and from your application data structures. In the case of Axis this can mean converting to and from an array of JavaBeans for the actual data, or using a custom serializer/deserializer, or using data binding in combination with Axis. I don't think it's good to design your web services interfaces around the limitations of the current platform, though (especially since the platforms are all becoming more capable as time goes by).

 - Dennis

Reply via email to