Mam problem z wczytywaniem z pliku xml. Zobaczcie tutaj mam plik xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <patients> <patient id="1" imie="Agata" nazwisko="Jakas" pesel="666666666"> <badania> <badanie filename="plik.cvs" opisbadania="W normie" stringdata="06/30/2014 18:43:18" /> </badania> </patient> </patients>**Poniżej kod czy może ktoś zerknąć czy jest to dobrze. **
public void loadXML(File file) {
this.clear();
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
System.out.println("Element główny: "
+ doc.getDocumentElement().getNodeName());
NodeList nodeLst = doc.getElementsByTagName("patient");
for (int s = 0; s < nodeLst.getLength(); s++) {
Node fstNode = (Node) nodeLst.item(s);
Patient p = new Patient();
String id = ((Element)fstNode).getAttribute("id");
p.setId(id);
String imie = ((Element) fstNode).getAttribute("imie");
p.setImie(imie);
String nazwisko = ((Element)fstNode).getAttribute("nazwisko");
p.setNazwisko(nazwisko);
String pesel = ((Element)fstNode).getAttribute("pesel");
p.setPesel(pesel);
this.add(p);
NodeList badaniaList= ((Element)fstNode).getElementsByTagName("badanie");
for ( int i = 0; i < badaniaList.getLength(); i++)
{
Node lstNode = (Node) badaniaList.item(s);
PlotFile b = new PlotFile();
String fileName = ((Element)lstNode).getAttribute("fileName");
b.setFileName(fileName);
String stringData = ((Element)lstNode).getAttribute("");
b.setdataString(stringData);
String opisBadania = ((Element)lstNode).getAttribute("opisBadania");
b.setOpis(opisBadania);
p.getList().add(b);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Prosiłbym o pomoc jakąś dobrą duszyczkę.