Hi all,
I'm using Castor to bind an XML document starting from an XML Schema.
All is working fine and normally I haven't any problem.
I'm using an XML Schema do describe this XML:
<MCMJ_RESULTS>
<ERROR_CODE>0000</ERROR_CODE>
<ERROR_MESSAGE>Pin updated</ERROR_MESSAGE>
</MCMJ_RESULTS>
Now I would like to fill my class also if I receive an XML like:
<MCMJ_RESULTS>
<ERROR_CODE>0000</ERROR_CODE>
<ERROR_MESSAGE>Pin updated</ERROR_MESSAGE>
<Test>Adds</Test>
</MCMJ_RESULTS>
I wrote Test but is possible that I receive Test1, or Object, or
something else and is also possible that I receive more other nodes.
To load my XML I'm using this:
list = (MCMJ_RESULTS)MCMJ_RESULTS.unmarshal(new StringReader(sw));
In this case it's normal that I cannot to validate the XML but I would
like to be able to read ERROR_CODE and ERROR_MESSAGE using:
ris=list.getERROR_CODE();
Now my code is not working because after the unmarshal I'm receiving
list=null.
If I didn't be cleare please ask me more detail.
Someone can help me to solve this problem?
Thank you.
Fenice - 21 Nov 2006 08:16 GMT
> Someone can help me to solve this problem?
I solved my problem :-)
MCMJRESULTS lista=null;
Unmarshaller unmar = new Unmarshaller(MCMJ_RESULTS.class);
unmar.setIgnoreExtraElements(true);
unmar.setIgnoreExtraAttributes(true);
unmar.setValidation(false);
try
{
list = (MCMJ_RESULTS)unmar.unmarshal(new StringReader(sw));
}
catch (ValidationException ex)
{
logger.warn("Errore Validazione WebService UpdatePin:
"+ex.getMessage());
}
catch (MarshalException ex)
{
logger.warn("Errore WebService UpdatePin: "+ex.getMessage());
}