I hope I fix this, but you only need to increase the score every time you add one employer
File file = new File("out" + i + ".xml"); FileOutputStream fos = new FileOutputStream(file, true); appendStuff("<Employees>",file); while (xsr.nextTag() == XMLStreamConstants.START_ELEMENT) { count++; t.transform(new StAXSource(xsr), new StreamResult(fos)); if(count == 100) { count = 0; i++; appendStuff("</Employees>",file); fos.close(); file = new File("out" + i + ".xml"); fos = new FileOutputStream(file, true); appendStuff("<Employees>",file); } }
Its not very nice, but you get the idea
private static void appendStuff(String content, File file) throws IOException { FileWriter fw = new FileWriter(file.getAbsoluteFile(),true); BufferedWriter bw = new BufferedWriter(fw); bw.write(content); bw.close(); }
source share