Hi Werner,

I found a solution. If I use the 'matches' attribute in combination with the 
'location' attribute. The docs are a bit misleading though: 

http://www.castor.org/xml-mapping.html#The-%3Cbind-xml%3E-element

They say that the matches attribute is a standard regular expression, but I 
found this not to be the case. I had to use a space seperated list of the 
elements and then it would work. My mapping file now looks like this:

<field name="devicesUnchanged" type="string" collection="array" >
        <bind-xml matches="IpAddress MacAddress" location="DevicesUnchanged" 
node="element" />
</field>

This results in all the elements inside the DevicesUnchanged tag to be 
unmarshalled into my String[].

Regards,

Kevin.

-----Original Message-----
From: Werner Guttmann [mailto:[email protected]] 
Sent: 07 March 2011 18:41
To: [email protected]
Cc: Kilroy, Kevin
Subject: Re: [castor-user] Unmarshal XML that contains 'choice' elements

Hi Kevin,

can I take it that you are generating Java sources from the XML schema at hand 
? Or are you trying to manually map this structure ?

Kind Regards
Werner

On 07.03.2011 16:56, Kilroy, Kevin wrote:
> Hi,
> 
> I'm trying to unmarshal some XML that contains 'choice' xsd elements:
> 
> <DevicesUnchanged>
>         <IpAddress>123.456</IpAddress>
>         <MacAddress>asdf</MacAddress>
>         <IpAddress>456.789</IpAddress>
>         <IpAddress>456.7892</
> IpAddress>
>         <IpAddress>456.78900</IpAddress> </DevicesUnchanged>
> 
> Where IpAddress and MacAddress are choice elements in the XSD:
> 
> <element name="DevicesUnchanged" minOccurs="0" maxOccurs="1">
>                 <complexType>
>                     <choice minOccurs="0" maxOccurs="unbounded">
>                         <element name="MacAddress" type="string" />
>                         <element name="IpAddress" type="string" />
>                     </choice>
>                 </complexType>
> </element>
> 
> What I am trying to achieve is to unmarshall the XML into a String[] in my 
> Java class. Does anybody know how what I have to specify in my 
> castor-mapping.xml to take care of the unmarshalling?
> 
> Thanks inadvance,
> 
> Kevin.
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to