Hi,
I created a structure classes similar to you follow the classes:
/* Class
Course */importjava.io.FileWriter;importjava.io.IOException;importorg.exolab.castor.xml.MarshalException;importorg.exolab.castor.xml.Marshaller;importorg.exolab.castor.xml.ValidationException;publicclassCourse
{}
}
}
Marshaller.marshal( course,
}
Course course =
Module module =
Level level =
Question[] question = {
};
course.
module.
level.
Course.marshal(
}
e.
}
e.
}
e.
}
}
}privateModule module;publicModule getModule()
{returnmodule;publicvoidsetModule( Module module ) {this.module=
module;publicstaticCourse unmarshal() {returnnull;publicstaticvoidmarshal(
String pathFileName, Course course ) throwsMarshalException,
ValidationException, IOException {newFileWriter( pathFileName )
);publicstaticvoidmain( String[] args )
{newCourse();newModule();newLevel();newQuestion( "1", "0", "De las siguientes
afirmaciones ordenador?", "Ondokoetatik"),newQuestion( "1", "0", "De las
siguientes afirmaciones ordenador?", "Ondokoetatik"),newQuestion( "1", "0", "De
las siguientes afirmaciones ordenador?", "Ondokoetatik")setModule( module
);setLevel( level );setQuestion( question );try{"C:\\CastorTeste.xml", course
);catch( MarshalException e ) {printStackTrace();catch( ValidationException e )
{printStackTrace();catch( IOException e ) {printStackTrace();
/* Class Module */public
}
}
}
/* Class Level */public
}
}
}classLevel {privateQuestion[] question;publicQuestion[] getQuestion()
{returnquestion;publicvoidsetQuestion( Question[] question ) {this.question=
question;
/* Class Question */public
}
}
}
}
}
}
}
}
}
}
and the generated xml was
/* CastorTeste */
<?xml version="1.0" encoding="UTF-8"?>
<course>
<module>
<level>
<question>
<EText>Ondokoetatik</EText>
<text>De las siguientes afirmaciones ordenador?</text>
<nivel>0</nivel>
<id>1</id>
</question>
<question>
<EText>Ondokoetatik</EText>
<text>De las siguientes afirmaciones ordenador?</text>
<nivel>0</nivel>
<id>1</id>
</question>
<question>
<EText>Ondokoetatik</EText>
<text>De las siguientes afirmaciones ordenador?</text>
<nivel>0</nivel>
<id>1</id>
</question>
</level>
</module>
</course>
so, this is the expected xml file by castor try it,
Regards,
*-----------------------------------------------------*
|| Marcelo Henrique De Oliveira Lima
|| Ciência da Computação - UECE
|| Linux User #399803
|| Slackware GNU/Linux Powered!
*-----------------------------------------------------*
----- Mensagem original ----
De: Jesus Lopez <[EMAIL PROTECTED]>
Para: [email protected]
Enviadas: Sexta-feira, 30 de Maio de 2008 7:24:00
Assunto: RE: Res: [castor-user] castor doesn´t unmarshal all my fields
-->I use this to execute the process:
FileInputStream fi=new FileInputStream(rutaXMLTema);
InputStreamReader is= new InputStreamReader(fi,"UTF-8");
Course pregsTema = Course.unmarshal(is);
Module moduleTema = pregsTema.getModule();
Level levelTema = moduleTema.getLevel();
listaPreguntasTema = levelTema.getQuestion();
for(int i=0;i<listaPreguntasTema.length;i++){
Question q=listaPreguntasTema[i];
.........
}
-->The XML is this:
<?xml version="1.0" encoding="UTF-8"?>
<course>
<module>
<level>
<question id="1" nivel="0" Text="De las siguientes afirmaciones ordenador?"
EText="Ondokoetatik">
</question>
.......
--> The bean:
public class Question implements java.io.Serializable {
private java.lang.String _id;
private java.lang.String _nivel;
private java.lang.String _text;
private java.lang.String _EText;
....
--> As I know, I don´t use a mapping file.
When I check, "q" only has got "id" and "nivel", and "Text" and "EText" with
null value.
I don´t know what can I do
Thanks
-----Original Message-----
From: Werner Guttmann [mailto:[EMAIL PROTECTED]
Sent: jueves, 29 de mayo de 2008 22:24
To: [email protected]
Subject: Re: Res: [castor-user] castor doesn´t unmarshal all my fields
Exactly. And for this to work, some (just a few) naming conventions have to be
met.
Werner
Marcelo Henrique wrote:
> Hi,
> are you using some mapping file? Because if not you're using castor default
> behavior that is through refletion to get the fields and fill the object.
>
> Regards,
>
> *-----------------------------------------------------*
> || Marcelo Henrique De Oliveira Lima
> || Ciência da Computação - UECE
> || Linux User #399803
> || Slackware GNU/Linux Powered!
> *-----------------------------------------------------*
>
>
>
> ----- Mensagem original ----
> De: Jesus Lopez <[EMAIL PROTECTED]>
> Para: [email protected]
> Enviadas: Quinta-feira, 29 de Maio de 2008 7:31:46
> Assunto: [castor-user] castor doesn´t unmarshal all my fields
>
>
> When I use castor to
> convert one XML file to Object, castor doesn´t unmarshal all my
> fields, only both first ones, and the rest with "null" value.
> I don`t understand
> this ...
>
> For example, here
> castor only unmarshal "id" and "nivel", and "Text" and "EText" with
> null
> value:
>
> <?xml
> version="1.0"
> encoding="UTF-8"?>
> <course>
> <module>
> <level>
> <question
> id="1" nivel="0" Text="De las siguientes afirmaciones, ¿cuál de ellas
> se ajusta mejor a la definición de ordenador?" EText="Ondokoetatik,
> zein da">
>
> </question>
> ....
>
>
> Thanks a
> lot
>
>
> Jesús López Lobo
> ************************************ DISCLAIMER
> *****************************************
> This message may contain confidential, proprietary or legally
> privilegedinformation.
> If you are not the intended recipient of this message, please notify it tothe
> sender and delete without resending or backing it, as it is legallyprohibited.
>
>
> ************************************* AVISO LEGAL
> ****************************************
>
> Este mensaje puede contener información confidencial, en propiedad
> olegalmente protegida.
> Si usted no es el destinatario, le rogamos lo comunique al remitentey proceda
> a borrarlo, sin reenviarlo ni conservarlo, ya que su uso no autorizado
> estáprohibido legalmente.
>
> **********************************************************************
> *******************
>
>
>
> Abra sua conta no Yahoo! Mail, o único sem limite de espaço para
>armazenamento!
> http://br.mail.yahoo.com/
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
********************************** DISCLAIMER *******************************
This message may contain confidential, proprietary or legally privileged
information.
If you are not the intended recipient of this message, please notify it to the
sender and delete without resending or backing it, as it is legally prohibited.
********************************** AVISO LEGAL ******************************
Este mensaje puede contener información confidencial, en propiedad o legalmente
protegida.
Si usted no es el destinatario, le rogamos lo comunique al remitente y proceda
a borrarlo, sin reenviarlo ni conservarlo, ya que su uso no autorizado está
prohibido legalmente.
******************************************************************************
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
classQuestion {privateString id;privateString nivel;privateString
text;privateString eText;publicQuestion( String id, String nivel, String text,
String eText ) {this.id= id;this.nivel= nivel;this.text= text;this.eText=
eText;publicString getId() {returnid;publicvoidsetId( String id ) {this.id=
id;publicString getNivel() {returnnivel;publicvoidsetNivel( String nivel )
{this.nivel= nivel;publicString getText() {returntext;publicvoidsetText( String
text ) {this.text= text;publicString getEText()
{returneText;publicvoidsetEText( String text ) {eText= text;classModule
{privateLevel level;publicLevel getLevel() {returnlevel;publicvoidsetLevel(
Level level ) {this.level= level;
Abra sua conta no Yahoo! Mail, o único sem limite de espaço para
armazenamento!
http://br.mail.yahoo.com/