XPathDocument also reads the complete document into memory, which is necessary to support all XPath axes , such as previous-native, previous, ancestor, parent, child, descendant, next-brother, next.
If you want to make XPath or XQuery queries without loading the entire document into memory, you need to study specialized XML databases, or at least SQL databases with an XML data type that supports XQuery. For example, MS SQL Server has an XML data type and supports some (in my opinion, limited) version of XQuery.
Martin honnen
source share