Hello Everyone,

I worked for hours on this issue, asked a friend, searched in maillist
with no success.

Hopefully anyone can give me a hint what i am doing wrong.

Thanks
Alexander Kunkel

###########################
I get following Exception
###########################
Illegal Text data found as child of: label
  value: "MyText"{file: [not available]; line: 2; column: 36}
        at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:707)
        at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:563)
        at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:784)
        at test.castor.SimpleTest.fromXml(SimpleTest.java:44)
        at test.castor.SimpleTest.main(SimpleTest.java:25)
Caused by: org.xml.sax.SAXException: Illegal Text data found as child
of: label
  value: "MyText"


######################
My Testclass
######################
public class SimpleTest {
    public static void main(String[] args) throws Exception {
        Label label = new Label();
        label.setText("MyText");
        label.setLanguage("DE");
        
        // writes the correct XML file
        toXml("test.xml", label);
        
        // but can't unmarshall current written XML 
        Object o = fromXml("test.xml", Label.class);

        System.out.println("ready");
    }

    public static void toXml(String file, Object o) throws Exception {
        Writer writer = new FileWriter(new File(file));
        Mapping mapping = new Mapping();
        mapping.loadMapping("mapping.xml");
        Marshaller marshaller = new Marshaller(writer);
        marshaller.setMapping(mapping);
        marshaller.marshal(o);
        writer.close();
    }

    public static Object fromXml(String file, Class clazz)
                                                  throws Exception {
        Reader reader = new FileReader(file);
        Mapping mapping = new Mapping();
        mapping.loadMapping("mapping.xml");
        Object o = Unmarshaller.unmarshal(clazz, reader);
        reader.close();
        return o;
    }
}

#####################
My Data Class
#####################
public class Label implements Serializable {
    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getLanguage() {
        return language;
    }
    
    public void setLanguage(String language) {
        this.language = language;
    }

    private String language;
    private String text;
}


#####################
My Mapping
#####################
<?xml version="1.0"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
<mapping>
  <class name="test.castor.Label">
    <map-to xml="label" />
    <field name="language" type="java.lang.String"
           get-method="getLanguage" set-method="setLanguage">
      <bind-xml name="language" node="attribute" />
    </field>
    <field name="text" type="java.lang.String">
      <bind-xml node="text" />
    </field>
  </class>
</mapping>

#################
My test.xml
#################
<?xml version="1.0" encoding="UTF-8"?>
<label language="DE">MyText</label>




        

        
                
___________________________________________________________ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de

-------------------------------------------------
If you wish to unsubscribe from this list, please 
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to