XPathDocument vs XmlDocument

I am developing a blogging engine in ASP.NET and one repository is implemented to use XML files as a data warehouse. The XML repository will be mainly used for local use and testing. Now, although this may not be a problem with today's computers, which have a lot of available memory and processing power, I nevertheless wanted to know some specific details:

  • XPathDocument is a read-only document, while an XmlDocument is a read / write document. therefore, XPathDocument is lighter than XmlDocument because it lacks write capabilities.
  • I know for sure that when loading an XML document using XmlDocument, it loads the entire document into memory, this can be a problem if the document is large. Does XPathDocument do the same? if so, how can I read a single node or a set of nodes from an XML document without first loading the entire document into memory? I know that I can use XmlTextReader, but that means that I have to parse the whole document when I access nodes in sequence. I want to be able to query XML documents with an XPath expression.

In any case, if the size of the object graphs is not much different (XmlDocument and XPathDocument), it will not hurt to just complete the task, but I want to implement the best possible solution here.

Thanks in advance [:

+7
source share
1 answer

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.

+6
source

All Articles