<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Querying LINQ to XML Nodes in Reverse Document Order with Better Performance</title><link>http://blogs.msdn.com/ericwhite/archive/2009/06/24/querying-linq-to-xml-nodes-in-reverse-document-order-with-better-performance.aspx</link><description>[Blog Map] (Update June 25, 2009 - fixed bugs in event handlers associated with deleting last node and inserting node at beginning of list) Occasionally I need to query LINQ to XML nodes in reverse document order. I’m currently writing some LINQ to XML</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Querying LINQ to XML Nodes in Reverse Document Order with Better Performance</title><link>http://blogs.msdn.com/ericwhite/archive/2009/06/24/querying-linq-to-xml-nodes-in-reverse-document-order-with-better-performance.aspx#9804743</link><pubDate>Fri, 26 Jun 2009 07:22:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9804743</guid><dc:creator>Rick Jelliffe</dc:creator><description>&lt;p&gt;You say &amp;quot;The need to process nodes in reverse document order is rare&amp;quot; but that is only if you remove the scenario of processing documents from what people do with XML. &lt;/p&gt;
&lt;p&gt;Database people have seemed congenitally certain that whatever they need is all that document processing people need. But it isn't so. &lt;/p&gt;
&lt;p&gt;In XML, you can write that an element X has a label Y with a value Z as&lt;/p&gt;
&lt;p&gt; &amp;lt;X Y=&amp;quot;Z&amp;quot; /&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;lt;X&amp;gt;&amp;lt;Y&amp;gt;Z&amp;lt;/Y&amp;gt;&amp;lt;/X&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;lt;label Y=&amp;quot;Z&amp;quot;&amp;gt;&amp;lt;X/&amp;gt;&amp;lt;/label&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;lt;container&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;&amp;lt;containerPr&amp;gt;&amp;lt;Y&amp;gt;Z&amp;lt;/Y&amp;gt;&amp;lt;/containerPr&amp;gt;&amp;lt;X/&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;lt;/container&amp;gt;&lt;/p&gt;
&lt;p&gt;and so on. &lt;/p&gt;
&lt;p&gt;So the heuristic for XML processing systems should not be that &amp;quot;forward axis is normal, other axes are weird&amp;quot; but rather something like &amp;quot;processing one element requires accessing other elements in inverse proportion to their degree of separation.&amp;quot; &lt;/p&gt;
&lt;p&gt;Indeed, you could classify documents, schemas and programs by the degrees of separation (XPath location steps needed to process each node.) I would guess an average (mode) of 2 for HTML, 4 for ODF and 5 for OOXML.&lt;/p&gt;
</description></item><item><title>re: Querying LINQ to XML Nodes in Reverse Document Order with Better Performance</title><link>http://blogs.msdn.com/ericwhite/archive/2009/06/24/querying-linq-to-xml-nodes-in-reverse-document-order-with-better-performance.aspx#9805946</link><pubDate>Fri, 26 Jun 2009 23:45:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9805946</guid><dc:creator>EricWhite</dc:creator><description>&lt;P&gt;Hi Rick,&lt;/P&gt;
&lt;P&gt;I believe that you are right that 'document-centric' XML tree processing is the scenario that requires the most from XML processing systems, including the ability to process nodes in reverse document order. &amp;nbsp;I certainly agree that document-centric XML processing requires more interesting axes than database scenarios. &amp;nbsp;I can't comment on ODF - I'm not an expert - but certainly there are places in Open XML that require quite a few (4-5) XPath location steps to process nodes.&lt;/P&gt;
&lt;P&gt;Regarding the decision of the designers of LINQ to XML to not include a doubly linked list for nodes, I believe it is a good one. &amp;nbsp;I've written a lot of LINQ to XML queries over Open XML documents, and til now, there have been only one or two scenarios that require reverse document order queries that perform well. &amp;nbsp;I just counted the nodes of one of my largest Open XML documents - it contains &amp;gt; 2,400,000 XML nodes in the main document part. &amp;nbsp;If there were a previous sibling node link in each node, then this would consume 8 meg that wouldn't be often used. &amp;nbsp;In addition, maintaining previous nodes would add additional processing burden - not a lot, but it adds up.&lt;/P&gt;
&lt;P&gt;But as seen here, it is trivial to add reverse document order axes that perform well. &amp;nbsp;We only need to enable them for the few scenarios where we actually need them.&lt;/P&gt;
&lt;P&gt;-Eric&lt;/P&gt;</description></item></channel></rss>