I’m relatively new to working with XML and am working with some rather large documents using the javax.xml.parsers.SAXParser .
The thing is: The information I need is near the top of the XML file and I don’t need to parse the entire document. — What is the “best” way to stop parsing a file when the relevant information has been identified?
(So far the only way I can think of is to throw an exception.)
Throwing an exception is the only way to stop it. See this IBM XML tip for an example.
You should probably implement your own exception to signal an intention to stop further processing. That way you will be able to distinguish between an intentional halt to processing, and an unintentional halt (when encountering some unexpected scenario etc.)