But that does not match what you are declaring in your object model when
seen in conjunction with the relevant mapping.

You define *one* collection of Strings only. This collection is meant to
hold all occurences of data that are mapped to the value attribute. The
fact that you are using a location prefix (texts/text in the original
fragment) just indicates that you want a slightly more complex XML layout.

Let's have a look at a simplified XML where there's no location prefix.
You are defining a Java member 'texts' that is capable of storing a
collection of Strings. In the <bind-xml> declaration, you are
instruction Castor to bind this to an attribute named 'value'.

Taking just this definition, you'd be able to to e.g. unmarshall XML as
follows:

<?xml version="1.0" encoding="Windows-1251"?>
<test value="Hello with Spaces"/>

The attribute could occur once only (as per definition), and within the
attribute you'd be able to enlist one or many Strings.

The fact that you are adding a location prefix (texts/text) introduces
additional XML artifacts, and in my opinion breaks the contract defined
by the original attribute definition (multivalued, attribute node).

I hope this makes sense.

Werner


Pokidov Dmitriy wrote:
> My expectation is two elements, because in my task I have xml about this:
> <combo-box>
> <values>
>   <item value="First item"/>
>   <item value="Second item">
> </values>
> </combo-box>
> I should correctly unmarshal this xml, I cannt change it's format.
> 
> 2008/7/10 Werner Guttmann <[EMAIL PROTECTED]>:
> 
>> Sorry, can you please rephrase your statement ? What is your expectation
>> ? That there is four elements, or not ?
>>
>> Werner
>>
>> Pokidov Dmitriy wrote:
>>> Hi, Werner
>>> No exceptions was throw, but in arraylist I have four items, but remains
>>> two.
>>>
>>> 2008/7/10 Werner Guttmann <[EMAIL PROTECTED]>:
>>>
>>>> Hi,
>>>>
>>>> What is actually your exceptation ? I have just taken your code
>>>> fragments and built a JUnit test case, and I cannot see anything wrong.
>>>>
>>>> Werner
>>>>
>>>> Pokidov Dmitriy wrote:
>>>>> Hi all.
>>>>>
>>>>> I have simple class:
>>>>> public class TestMappingClass {
>>>>>     List<String> texts = new ArrayList<String>();
>>>>>
>>>>>     public List<String> getTexts() {
>>>>>         return texts;
>>>>>     }
>>>>>
>>>>>     public void addText(String text) {
>>>>>         texts.add(text);
>>>>>     }
>>>>>
>>>>>     public void setTexts(List<String> texts) {
>>>>>         this.texts = texts;
>>>>>     }
>>>>> }
>>>>>
>>>>> mapping for this class:
>>>>>     <m:class name="test4.TestMappingClass">
>>>>>         <m:map-to xml="test"/>
>>>>>         <m:field name="texts" collection="arraylist"
>>>> type="java.lang.String"
>>>>>                 set-method="addText" get-method="getTexts">
>>>>>             <m:bind-xml name="value" node="attribute"
>>>>> location="texts/text"/>
>>>>>         </m:field>
>>>>>     </m:class>
>>>>>
>>>>> and xml that I want to unmarshall:
>>>>> <?xml version="1.0" encoding="Windows-1251"?>
>>>>> <test>
>>>>>   <texts>
>>>>>     <text value="Hello2"/> +
>>>>>     <text value="Hello with space"/>
>>>>>   </texts>
>>>>> </test>
>>>>>
>>>>> In unmarshall object I have four elements:
>>>>> Hello2,Hello,with,space.
>>>>>
>>>>> How I can declare mapping to unmarshall this xml correct?
>>>>>
>>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe from this list, please visit:
>>>>
>>>>    http://xircles.codehaus.org/manage_email
>>>>
>>>>
>>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>>
> 
> 

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

    http://xircles.codehaus.org/manage_email


Reply via email to