Hi,
I can't unmarshal an xml data file to a class with a Vector as attribute.
Suppose that I have a simple class like this:
public class SimpleObj {
private String sn;
private Vector itemList; //this attribute contains only String object
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public Vector getItemList() {
return itemList;
}
public void setItemList(Vector itemList) {
this.itemList = itemList;
}
}
I also have an xml file with the data to unmarshal:
<simple-obj>
<sn>21232CVX34</sn>
<item-list>first item</item-list>
<item-list>second item</item-list>
<item-list>third item</item-list>
</simple-obj>
I wrote the following mapping file:
<mapping>
<class name="SimpleObj" auto-complete="false">
<map-to xml="simple-obj"/>
<field name="sn" type="string" required="true" direct="false"
transient="false">
<bind-xml name="sn" node="element" reference="false"/>
</field>
<field name="itemList" type="string" required="true" direct="false"
transient="false" collection="vector">
<bind-xml name="item-list" node="element" reference="false"/>
</field>
</class>
</mapping>
Then I unmarshal the xml data file using the Castor APIs:
Mapping mapping = new Mapping();
mapping.loadMapping( "mapping.xml" );
Unmarshaller unmarshaller = new Unmarshaller(SimpleObj.class);
SimpleObj simpleObj = (SimpleObj)unmarshaller.unmarshal(new InputSource(new
FileReader("sample.xml")));
But I always get the exception:
org.xml.sax.SAXException: Illegal Text data found as child of: item-list
value: "first item"
at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:806)
at
org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:1038)
at org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1403)
at
org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator.java:1480)
How can I modify the xml data file or the mapping file in order to correctly unmarshal
data to SimpleObj class?
Thanks,
Alessandro
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user