i'm making simple javafx application make table data analysis of blastp outputs in xml format. isn't incredibly slow want make program efficient can. added code cut down lot because real files quite large convey general outline. i'm not looking write code me suggestions when have load large amount of xmls take @ api or try loading files object. xml table follows:
gather files filechooser
public void listchange() throws //allexceptions// { list<file> files = fc.showopenmultipledialog(new stage()); if (files != null) { files.foreach(f -> { try { xmldatalist.add(xmlfile(f.getpath())); } catch (//allexceptions//) { e.printstacktrace(); } }); } }
run files through sax parser object xmldata
public xmldata xmlfile(string path) throws //allexceptions// { if (path.endswith(".xml")) { saxparserfactory parserfactor = saxparserfactory.newinstance(); saxhandler saxh = new saxhandler(); saxparser parser = parserfactor.newsaxparser(); parser.parse(path, saxh); int suffix = 1; string pname = path.substring(path.lastindexof("\\")+1, path.length() - 4), temp = pname; arraylist<string> xmldataname = new arraylist<>(); xmldataarraylistist.foreach(x -> xmldataname.add(x.pname)); system.out.println("finished"); return new xmldata(saxh.hitlist, temp); } else{ return null; } }
sax handler creates list of objects called hsps(high scoring protein sequences) , within object object hsp(high scoring protein).
public class saxhandler extends defaulthandler { public arraylist<hsps> hitlist = new arraylist<>(); @override public void startelement(string u, string ln, string ele, attributes at) throws saxexception { switch(ele){ case "hit": hsps = new hsps(); break; case "hsp": hsp = new hsp(); break; } } @override public void endelement(string uri, string ln,string ele) throws saxexception { switch(ele){ case "hit_hsps": hitlist.add(hsps); break; case "hsp": hsps.hspl.add(hsp); break; case "hit_def": hsps.name = content; break; case "hit_id": hsps.id = content; break; } } @override public void characters(char[] ch, int start, int length) throws saxexception { content = string.copyvalueof(ch, start, length); } }
the object hsps contains list of hsp , name of protein these sequences belong to. hsp object contains number of strings data. table reads hsp within hsps within xmlfile object.
so after guess question is, optimal way transfer correct items table? xml files contain amount more data want few items. if addition information needed ask.
i have no experience concurrence if increase efficiency, i'll it.
try simple-xml simple name suggested.
maven dependency
<dependency> <groupid>org.simpleframework</groupid> <artifactid>simple-xml</artifactid> <scope>compile</scope> <version>2.7.1</version> </dependency>
sample code
package com.vibhs.stack.overflow.xml; import java.io.file; import org.simpleframework.xml.serializer; import org.simpleframework.xml.core.persister; public class parser { private serializer serializer = new persister(); public void createxml(object object, file destination) throws exception { serializer.write(object, destination); } public object readxml(class<?> clazz, file source) throws exception { return serializer.read(clazz, source); } }