I have a java code that reads various xml files, filters cetain elements and writes the results of these files to one large xml file. Problem is, when the files are read into the large xml, all the nodes are sorted alphabetically. I tried looking for an API that's responsible for this but I cant find one. Can anyone please help?? Here's the portion of my code that writes the file:
private static void writeFile(Document doc, ArrayList docIdList,
BufferedWriter output) {
try {
Element loElmt = null;
NodeList loDocumentList = XMLUtil.getNodeList(doc,
"/XML_EXPORT_FILE/DOCUMENT");
for (int i = 0; i < loDocumentList.getLength(); i++) {
Element loDocument = (Element) loDocumentList.item(i);
String lsDocCode = loDocument.getAttribute("DOC");
String lsDocId = loDocument.getAttribute("DOCS");
//System.out.println(lsDocCode + "\t\t" + lsDocId);
// doc identifer is in list
if (isDocInList(docIdList, lsDocCode, lsDocId)) {
String document = XMLUtil.transformToString(loDocument);
System.out.println("Writing " + lsDocCode + "\t\t"
+ lsDocId + " to output file");
output.write(document);
}
}
} catch (Exception e) {
e.printStackTrace();
}