Hello,

I've just tried the Castor XML binding and have experienced a strange
behaviour that smells like a bug to me.

Here's my XML Schema:

<xs:schema
  xmlns:xs='http://www.w3.org/2001/XMLSchema'>

 <xs:element name='AddressBook'>
  <xs:complexType>
   <xs:sequence>
    <xs:element ref='Contacts'/>
   </xs:sequence>
  </xs:complexType>
 </xs:element>

 <xs:element name='Contacts'>
  <xs:complexType>
   <xs:sequence>
    <xs:element ref='Contact' maxOccurs='unbounded'/>
   </xs:sequence>
  </xs:complexType>
 </xs:element>

 <xs:element name='Contact'>
  <xs:complexType>
   <xs:attribute name='FirstName' type='xs:string' use='optional'/>
   <xs:attribute name='LastName' type='xs:string' use='optional'/>
   <xs:attribute name='DefaultEmail' type='xs:string' use='optional'/>
  </xs:complexType>
 </xs:element>
</xs:schema>


Here's some sample data (addressbook.xml):

<?xml version="1.0" encoding="UTF-8"?>

<AddressBook>
    <Contacts>
        <Contact FirstName="Hansi" LastName="Hinterseer"
        DefaultEmail="[EMAIL PROTECTED]"/>

        <Contact FirstName="Blaze" LastName="Bayley"
        DefaultEmail="[EMAIL PROTECTED]"/>
    </Contacts>
</AddressBook>


Here's the Java code:

import java.io.IOException;
import java.io.FileReader;
import java.io.FileWriter;

import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.ValidationException;


/**
 * Minimale Beispielanwendung f�r das Addressbuch mit Castor-XML
Databinding.
 */
public class Main {
    public static void main(String[] args) {
        // Adressbuch von XML-Datei laden
        AddressBook ab = null;

        try {
            ab = AddressBook.unmarshal(new
FileReader("addressbook.xml"));
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } catch (MarshalException me) {
            me.printStackTrace();
        } catch (ValidationException ve) {
            ve.printStackTrace();
        }

        System.out.println(ab.getContacts());

        if (ab != null) {
            try {
                ab.marshal(new FileWriter("out.xml"));
            } catch (IOException ioe) {
                ioe.printStackTrace();
            } catch (MarshalException me) {
                me.printStackTrace();
            } catch (ValidationException ve) {
                ve.printStackTrace();
            }
        }

    }
}

Now, why is ab.getContacts() == null even though there is a Contacts
element in the XML file?! Castor version is the latest release: 0.9.3.9.

Gerhard H�ring
OPUS GmbH
http://www.opus-gmbh.net/ 

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

Reply via email to