It's not a secret anymore!
The moose likes XML and Related Technologies and the fly likes Go directly to a document section Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Go directly to a document section" Watch "Go directly to a document section" New topic

Go directly to a document section

Emili Calonge
Ranch Hand

Joined: May 17, 2003
Posts: 84
Ok, I'm new to xml so maybe I don't use the adecuate words, but I hope I make myself clear. I have a large xml document which contains information about files, structured this way:
So I have thousands of files in this document, now I want to acces to one file, for example file1, which can be anywhere in the document. Is there a way to do this?? I know I can read the entire document until I find the file, but I'm asking for a more efficient way of doing it. Thanks for the help.
[ October 18, 2005: Message edited by: Emili Calonge ]
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Many XML technologies (e.g. DOM, XSLT) read the whole file in any case, before you can start looking for particular parts of it. And any solution you come up with is going to have to read at least the whole file down to the part you are looking for. So my suggestion would be to look for a solution that works for you. When you get more experience in XML then you will be able to recognize good and bad solutions.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
If all you need out of the XML document is the content of one <FILE> element, this is an ideal candidate for SAX processing. The reasons being:
1. You can abort reading the file after the target information has been found.
2. The memory requirements are much less than the DOM approach which always parses the entire file into memory.

I agree. Here's the link:
subject: Go directly to a document section
It's not a secret anymore!