Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Sorting XML nodes in Java

807600Nov 29 2007
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();
		}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 27 2007
Added on Nov 29 2007
0 comments
1,496 views