Hi,

I'm using version 0.9.5.3 of Castor with the following schema:

-- XML schema (test-choice.xsd) 
-----------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
elementFormDefault="qualified" attributeFormDefault="unqualified">
        <xs:element name="root">
                <xs:annotation>
                        <xs:documentation>Comment describing your root 
element</xs:documentation>
                </xs:annotation>
                <xs:complexType>
                        <xs:sequence>
                                <xs:element name="element_1" type="xs:string"/>
                                <xs:choice>
                                        <xs:sequence>
                                                <xs:element name="element_2" 
type="xs:string"/>
                                                <xs:element name="element_3" 
type="xs:string" minOccurs="0"/>
                                        </xs:sequence>
                                        <xs:sequence>
                                                <xs:element name="element_2" 
type="xs:string" minOccurs="0"/>
                                                <xs:element name="element_3" 
type="xs:string"/>
                                        </xs:sequence>
                                </xs:choice>
                        </xs:sequence>
                </xs:complexType>
        </xs:element>
</xs:schema>
------------------------------------------------------------------------------------------

I need a schema that guarantees that element_2 or element_3 exists in the XML 
file. But it is also possible that both are part of the XML file. If there is 
another solution for the schema that solves my problem please let me know.

I generated the classes with the Source Generator from Castor and tried to 
unmarshal the following two XML files.

-- XML (file-1) 
---------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:noNamespaceSchemaLocation="test-choice.xsd">
        <element_1>Element 1</element_1>
        <element_2>Element 2</element_2>
</root>
-- XML (file-2) 
---------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:noNamespaceSchemaLocation="test-choice.xsd">
        <element_1>Element 1</element_1>
        <element_3>Element 3</element_3>
</root>
-------------------------------------------------------------------------------------------

I validated both files with XML-Spy and both are well-formed and valid.

With file-1 I don't have any problems during the Unmarshalling. But with file-2 
I get the following error message:

-- Error message 
--------------------------------------------------------------------------
ValidationException: The field '_element_2' (whose xml name is 'element_2') is 
a required field.;
   - location of error: XPATH: root
        at 
org.exolab.castor.xml.FieldValidator.validate(FieldValidator.java:203)
        at org.exolab.castor.xml.util.XMLClassDescriptorI...........
-------------------------------------------------------------------------------------------

I also tried it with version 0.9.5.4 of castor but it didn't fix my problem.

I would really appreciate it if somebody can help me or shows me a workaround.

Best regards

Christian
**************************************************************

Christian Zeiler 
Bedag Informatik AG
  Entwicklung 2 / CZE 
Gutenbergstrasse 3
3011 Bern 
Telefon: +41 (0)31 633 21 21 (633 24 14)
Fax:        +41 (0)31 
E-Mail:     mailto:[EMAIL PROTECTED] 
Internet:  www.bedag.ch 

**************************************************************

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-user

Reply via email to