You don't need to build the entire document tree in memory. You just have to use a sequential parser like SAX or StAX.
I'm sure there are better ways to do it, though.
I'm sure some handlers could be generalized a bit (for example, scanning for regular expressions). But I don't think that the SAX/commandline solution is much better than the SAX/program solution.
Am I missing something?