I have a massive XML file. However, I'm only interested in a single small subtree of this massive tree. I want to parse this subtree, but I don't want to waste time parsing the entire massive tree when I'm going to only be using a small part of it.
Ideally, I'd want to scan through the file until I find the start of this subtree, parse the subtree until I reach the end of it, and then not even bother reading the rest of the file. Maybe even describe the subtree I'm interested in with an XPath expression. Is there a way to do this using lxml? It looks like you might be able to do something like this using the iterparse()
method, but based on the docs, it looks like that doesn't produce a parsed object, which I want to use. Any suggestions?
(Using lxml is not required, but I want to use Python, and ideally I'd like it to be speedy.)