Chris:
The difference between the two examples you show amounts to whether or not there's a parent element, or wrapper, specified that's dedicated to containing the array. The first example uses a parent/wrapper; the second example does not because it throws the int-type element at the same level as the array elements.

The WS-I Basic Profile 1.0 does not mandate the use of a parent/wrapper. All it says is:
"In a DESCRIPTION, array declaration wrapper elements SHOULD NOT be named using the convention ArrayOfXXX."

Really, which way you go is a judgment/ease-of-use call on your part. I tend to find the dedicated wrapper to be easier since it avoids mixing the array elements up with other elements at the same level.

As for Axis, its WSDL2Java tool creates an ArrayOfWhatever class if it encounters a <complexType> named ArrayOfWhatever; the fact that it's just a wrapper for an array doesn't matter. To be WS-I-compliant, use some name other than ArrayOf... If I recall correctly, Axis' Java2WSDL tool always generates a soapenc:array for the actual array, regardless of the style specified.

A slight digression. For anyone using the .NET Framework, the presence or non-presence of a wrapper is determined by the use of an [XmlArray] or [XmlElement] attribute respectively on any collection type. The default is [XmlArray].

"Chris Williamson" <[EMAIL PROTECTED]> wrote:

Hey I have a question about arrays.

In the ws-i spec it states that arrays should be defined such as...

<complexType name="StringArray">
<xsd:sequence>
<xsd:element name="str" type="xsd:string" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
</complexType>

And this turns out...

<StringArray>
<str>blah</str>
<str>moreblah</str>
</StringArray>

Should arrays be defined in a complexType all to themselves? Or I noticed
that Axis supports something like this...

<complexType name="CompoundObject">
<xsd:sequence>
<xsd:element name="str" type="xsd:string" minOccurs="0"
maxOccurs="unbounded"/>
<xsd:element name="x" type="xsd:int"/>
</xsd:sequence>
</complexType>

Which translates to something like...

<CompoundObject>
<str>blah</str>
<str>moreblah</str>
<x>3</x>
</CompoundObject>

In Axis it translates to methods such as...

String[] a = compoundObject.getStr();
Integer b = compoundObject.getX();

Is it proper to declare an array as a separate object such as the first
definition? And then use it in a Compound object. Or is it ok to define an
array directly in the CompoundObject like in the second definition?

Thanks,

Chris



Reply via email to