Hi,
I have what should be a very simple unmarshal issue. Im using castor
1.3.1 but I had the same issue with 1.1.1. Im using a mapping xml and when
the unmarshal executes I get a MarshalException: Illegal Text data found as
child of: question
My xml is this...
<QuestionSet>
<question id="1" response="3">Question Text 1</question>
<question id="2" response="3">Question Text 2</question>
<question id="3" response="1">Question Text 3</question>
</QuestionSet>
My mapping file is this...
<?xml version="1.0" encoding="UTF-8"?>
<mapping>
<class name="test" auto-complete="false">
<map-to xml="QuestionSet"/>
<field name="questionList" type="Question"
collection="array">
<bind-xml name="question" node="element" />
</field>
</class>
<class name="Question">
<map-to xml="question"/>
<field name="id" type="string" direct="false" transient="false">
<bind-xml name="id" node="attribute" />
</field>
<field name="response" type="string" direct="false"
transient="false">
<bind-xml name="response" node="attribute" />
</field>
</class>
</mapping>
My 2 classes are here
public class test {
private Question[] questionList;
public Question[] getQuestionList() {
return questionList;
}
public void setQuestionList(Question[] questionList) {
this.questionList = questionList;
}
}
public class Question {
protected String id;
protected String response;
protected String text;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getResponse() {
return response;
}
public void setResponse(String response) {
this.response = response;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
And the code doing the unmarshalling is here...
test payload = null;
try {
String mappingFilePath = "testing.xml";
java.net.URL mapURL = this.getClass().getResource(mappingFilePath);
org.exolab.castor.mapping.Mapping mapping = new
org.exolab.castor.mapping.Mapping();
mapping.loadMapping(mapURL);
// Create a Reader to the file to unmarshal from
java.io.StringReader sr = new java.io.StringReader(xml);
// Create a new Unmarshaller
//org.exolab.castor.xml.Unmarshaller unmarshaller = new
org.exolab.castor.xml.Unmarshaller(test.class);
org.exolab.castor.xml.Unmarshaller unmarshaller = new
org.exolab.castor.xml.Unmarshaller(mapping);
//unmarshaller.setMapping(mapping);
unmarshaller.setValidation(false);
unmarshaller.setIgnoreExtraAttributes(true);
unmarshaller.setIgnoreExtraElements(true);
// Unmarshal to the object
payload = (test) unmarshaller.unmarshal(sr);
} catch (Exception e) {
e.printStackTrace();
}
Im sure its something simple but ive stared at the code for hours and tried
different things and cant seem to get anywhere.
If I remove the text between the <question></question> tags (ie, the
"question text 1", "question text 2", etc.) the unmarshal works fine and I
get my array of 3 question objects.
I really need to get at that data between the <question> tags, the question
text. I have no control over the format of the xml, thats the way im
receiving it so im stuck with it. Any help with the mapping to get that
part would be great.
Thanks in advance.
Jeff.
--
View this message in context:
http://old.nabble.com/Simple-unmarshal-problem-tp30076485p30076485.html
Sent from the Castor - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email