I'm trying to visualize a xml , in a jtable , at the moment it only shows me the last element of xml and the rest omits it , I'd like to know where the error is.
public void llenar()
{
SAXBuilder builder = new SAXBuilder();
File xmlFile = new File( "C:/ACME/empleados_ACME.xml" );
try
{
Document document = (Document) builder.build( xmlFile );
Element rootNode = document.getRootElement();
List list = rootNode.getChildren( "empleado" );
for ( int i = 0; i < list.size(); i++ )
{
Element tabla = (Element) list.get(i);
String nombreTabla = tabla.getAttributeValue("cédula");
List lista_datos = tabla.getChildren();
Object[][] listaTable = new Object[lista_datos.size()][9];
for ( int j = 0; j < lista_datos.size(); j++ )
{
Element datos = (Element)lista_datos.get( j );
listaTable [j][0] = nombreTabla;
String nombre = datos.getChildTextTrim("nombre_completo");
String[] parts = nombre.split(" ");
listaTable[j][1] = parts[0];
listaTable[j][2] = parts[1];
listaTable[j][3] = parts[2];
listaTable[j][4] = datos.getChildTextTrim("teléfono1");
listaTable[j][5]= datos.getChildTextTrim("teléfono2");
listaTable[j][6] = datos.getChildTextTrim("email");
listaTable[j][7] = datos.getChildTextTrim("dirección_domicilio");
listaTable[j][8] = datos.getChildTextTrim("fecha_nacimiento");
System.out.println( "\t"+listaTable [j][0]+"\t"+listaTable [j][1]+"\t\t"+listaTable [j][2]+"\t\t"+listaTable [j][3]+"\t\t"+listaTable [j][4]+"\t\t"+listaTable [j][5]+"\t\t"+listaTable [j][6]+"\t\t"+listaTable [j][7]+"\t\t"+listaTable [j][8]);
}
xmlTable.setModel(new javax.swing.table.DefaultTableModel(
listaTable,
new String [] {
"Cedula", "Nombre", "Apellido", "Apellido", "Telefono 1", "Telefono 2", "Email", "Direccion", "Fecha",
}
));
}
}catch ( IOException io ) {
System.out.println( io.getMessage() );
}catch ( JDOMException jdomex ) {
System.out.println( jdomex.getMessage() );
}
}