2
I have an XML like this:
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.8.0_101" class="java.beans.XMLDecoder">
<object class="java.util.ArrayList">
<void method="add">
<object class="modelo.Aluno">
<void property="cpf">
<int>321</int>
</void>
<void property="data_nasc">
<string>123</string>
</void>
<void property="email">
<string>aluno@aluno</string>
</void>
<void property="matricula">
<int>1</int>
</void>
<void property="nome">
<string>aluno 1</string>
</void>
</object>
</void>
<void method="add">
<object class="modelo.Aluno">
<void property="cpf">
<int>321</int>
</void>
<void property="data_nasc">
<string>123</string>
</void>
<void property="email">
<string>aluno@aluno</string>
</void>
<void property="matricula">
<int>1</int>
</void>
<void property="nome">
<string>aluno 2</string>
</void>
</object>
</void>
<void method="add">
<object class="modelo.Aluno">
<void property="cpf">
<int>321</int>
</void>
<void property="data_nasc">
<string>123</string>
</void>
<void property="email">
<string>aluno@aluno</string>
</void>
<void property="matricula">
<int>1</int>
</void>
<void property="nome">
<string>aluno 3</string>
</void>
I’m trying to read the objects as follows:
public /*ArrayList<Aluno>*/ void carregaAlunos()
{
Aluno[] alunos = new Aluno[3];
System.out.println("eeeeeee");
try{
XMLDecoder decoder = null;
try{
decoder = new XMLDecoder(
new FileInputStream("alunos.xml"));
alunos = (Aluno[]) decoder.readObject();//ESSA LINHA NÃO ESTÁ FUNCIONANDO
System.out.println("Alunos lidos: " + alunos.length);
for (Aluno a : alunos)
System.out.println(a.getNome());
} finally {
if (decoder != null)
decoder.close();
}
} catch (IOException e){
System.out.println(e.getMessage());
}
}
How to proceed?
Thanks in advance!
Any error message appears?
– Pablo Almeida