Florian,

Can you please create a new issue at http://jira.codehaus.org/browse/CASTOR, 
and attach all relevant files (self-contained and minimal XML schema, binding 
file (if used), builder properties (if used) and XML document instance used to 
produce the error). Once evertyhing has been uploaded, we'll be having a look.

And pretty please always make it clear what version of Castor/Java you are 
using, as this might be relevant.

Thanks in advance
Werner

> -----Original Message-----
> From: Florian Müller [mailto:[EMAIL PROTECTED] 
> Sent: Dienstag, 21. November 2006 19:07
> To: [email protected]
> Subject: [castor-user] XML - unable to unmarshal an unbounded 
> xml choice containing a number of value 0
> 
> Hi,
> 
> I am using castor since two months now to marshal and 
> unmarshal objects defined in a xml schema.
> Lately I discovered a strange behaviour of castor. I wanted 
> to marshall a Vector of known objects to xml. Therefore I 
> defined a xml schema with an unbounded choice to represent 
> the vector. It worked as expected until I started to 
> integrate primitive data types (numbers: xs:integer, xs:long, 
> ...) into my schema. As soon as I have two consecutive number 
> elements of the same type and the first of this elements 
> holds the value 0 (zero) unmarshalling fails with an 
> exception. Surprisingly there are no problems if I use 
> xs:string instead.
> 
> Maybe you can help me out.
> 
> Best regards
> Florian
> 
> To reduce complexity I reproduced the problem in a small example.
> 
> 
> EXAMPLE:
> --------
> 
> I use castor 1.0.5 and java 1.4.2_13 on WindowsXP SP2 at the 
> moment. If you are interested in, I can provide a zip file 
> with the explample eclipse project.
> 
> Schema:
> -------
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
> elementFormDefault="qualified">
>     <xs:element name="SequenceOfChoices" 
> type="SequenceOfChoicesType"></xs:element>
>     <xs:complexType name="SequenceOfChoicesType">
>         <xs:choice minOccurs="0" maxOccurs="unbounded">
>             <xs:element name="Int" type="xs:integer"/>
>         </xs:choice>
>     </xs:complexType>
> </xs:schema>
> 
> Ant target for schema classes generation:
> -----------------------------------------
> <target name="castor-gen-src" description="Generate Java 
> source files from XSD.">
>     <delete dir="${source.dir}/schema"/>
>     <mkdir dir="${source.dir}/schema"/>
>     <castor-srcgen file="${basedir}/schema.xsd"
>         todir="${source.dir}"
>         package="schema"
>         warnings="true"
>         properties="${basedir}/castorbuilder.properties"
>         verbose="true"
>     />
> </target>
> 
> castorbuilder.properties:
> -------------------------
> org.exolab.castor.builder.primitivetowrapper=true
> 
> Some simple test code:
> ----------------------
> try {
>     File file = new File("data/test.xml");
>     Writer writer = new FileWriter(file);
> 
>     SequenceOfChoices marshallMe = new SequenceOfChoices();
>     for (int i = 5; i >= -5; i = i - 1) {
>         SequenceOfChoicesTypeItem itemInt = new 
> SequenceOfChoicesTypeItem();
>         itemInt.setInt(new Integer(i));
>         marshallMe.addSequenceOfChoicesTypeItem(itemInt);
>     }
>     marshallMe.marshal(writer);
> 
>     Reader reader = new FileReader(file);
>     SequenceOfChoicesType unmarshalledObj = 
> SequenceOfChoices.unmarshal(reader);
>     SequenceOfChoicesTypeItem[] array = 
> unmarshalledObj.getSequenceOfChoicesTypeItem();
>     for (int i = 0; i < array.length; i++) {
>         System.out.println(i + ": " + array[i].getChoiceValue());
>     }
> } catch (Exception e) {
>     e.printStackTrace();
> }
> 
> Generated xml:
> --------------
> <?xml version="1.0" encoding="UTF-8"?>
> <SequenceOfChoices>
>     <Int>5</Int>
>     <Int>4</Int>
>     <Int>3</Int>
>     <Int>2</Int>
>     <Int>1</Int>
>     <Int>0</Int>
>     <Int>-1</Int>
>     <Int>-2</Int>
>     <Int>-3</Int>
>     <Int>-4</Int>
>     <Int>-5</Int>
> </SequenceOfChoices>
> 
> The exception occurs as soon as unmarshall is called:
> -----------------------------------------------------
> element "Int" occurs more than once. (parent class: 
> schema.SequenceOfChoicesTypeItem)
>  location: /_items/Int{file: [not available]; line: 14; column: 18}
>     at 
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:732)
>     at 
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:588)
>     at 
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:809)
>     at schema.SequenceOfChoices.unmarshal(SequenceOfChoices.java:108)
>     at test.TestSchema.main(TestSchema.java:36)
> Caused by: ValidationException: element "Int" occurs more than once. 
> (parent class: schema.SequenceOfChoicesTypeItem)
>  location: /_items/Int
>     at
> org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHan
> dler.java:989)
>     at
> org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHan
> dler.java:1121)
>     at 
> org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1403)
>     at
> org.apache.xerces.validators.common.XMLValidator.callEndElemen
> t(XMLValidator.java:1436)
>     at
> org.apache.xerces.framework.XMLDocumentScanner$ContentDispatch
er.dispatch(XMLDocumentScanner.java:1205)
>     at
> org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDo
> cumentScanner.java:381)
>     at 
> org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1035)
>     at 
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:718)
>     ... 4 more
> Caused by: ValidationException: element "Int" occurs more than once. 
> (parent class: schema.SequenceOfChoicesTypeItem)
>  location: /_items/Int
>     at
> org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHan
> dler.java:989)
>     at
> org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHan
> dler.java:1121)
>     at 
> org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1403)
>     at
> org.apache.xerces.validators.common.XMLValidator.callEndElemen
> t(XMLValidator.java:1436)
>     at
> org.apache.xerces.framework.XMLDocumentScanner$ContentDispatch
er.dispatch(XMLDocumentScanner.java:1205)
>     at
> org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDo
> cumentScanner.java:381)
>     at 
> org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1035)
>     at 
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:718)
>     at 
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:588)
>     at 
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:809)
>     at schema.SequenceOfChoices.unmarshal(SequenceOfChoices.java:108)
>     at test.TestSchema.main(TestSchema.java:36)
> Caused by: ValidationException: element "Int" occurs more than once. 
> (parent class: schema.SequenceOfChoicesTypeItem)
>  location: /_items/Int
>     at
> org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHan
> dler.java:989)
>     at
> org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHan
> dler.java:1121)
>     at 
> org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1403)
>     at
> org.apache.xerces.validators.common.XMLValidator.callEndElemen
> t(XMLValidator.java:1436)
>     at
> org.apache.xerces.framework.XMLDocumentScanner$ContentDispatch
er.dispatch(XMLDocumentScanner.java:1205)
>     at
> org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDo
> cumentScanner.java:381)
>     at 
> org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1035)
>     at 
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:718)
>     at 
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:588)
>     at 
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:809)
>     at schema.SequenceOfChoices.unmarshal(SequenceOfChoices.java:108)
>     at test.TestSchema.main(TestSchema.java:36)
> 
> 
> 
> 
>       
>               
> ___________________________________________________________
> Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen 
> Yahoo! Mail: http://mail.yahoo.de
> 
> ---------------------------------------------------------------------
> 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