开发者

XPathDocument vs. XmlDocument

I'm developing a blogging engine in ASP.NET and one the repositories is implemented to use XML files as the data store. the XML repository will mainly be used for local use and testing purposes. now although it might not be that of an issue with today's computers which have lots of memory available and processing power, but nevertheless I wanted to know some specific details :

  • XPathDocument is a read-only document whereas the XmlDocument is a read/write document. Hence, is XPathDocument more lightweight than XmlDocument since it lacks the writing capabilities?
  • I know for sure that when you load an XML document with XmlDocument it loads the entire document in memory, that might be a problem if the document size is big. Does XPathDocument do the same thing? if so, how can I read a single node or a set of nodes from an XML document without loading the entire document in memory first? I know I can use XmlTextReader but that means I have to parse the entire document as I access the nodes sequentially. I want to be able to query XML documents with an XPath expression.

Anyway, if the size of the object graphs don't differ much (XmlDocument and XPathDocument) it won't hurt to just get the job done, but I 开发者_Python百科want to implement the best possible solution here.


XPathDocument reads the complete document into memory as well, that is needed to support all the XPath axes like preceding-sibling, preceding, ancestor, parent, child, descendant, following-sibling, following.

If you want to do XPath or XQuery queries without loading the whole document into memory then you have to look into specialized XML databases or at least into SQL databases with an XML data type with XQuery support. MS SQL server for instance has an XML data type and supports some (in my view rather limited) version of XQuery on that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜