<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>XML</title>
        <link>http://geekswithblogs.net/paulp/category/3197.aspx</link>
        <description>XML</description>
        <language>en-US</language>
        <copyright>Paul Petrov</copyright>
        <managingEditor>paul@petrovs.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Watch Those Lazy XPath Queries</title>
            <link>http://geekswithblogs.net/paulp/archive/2006/07/28/86569.aspx</link>
            <description>&lt;P&gt;I notice often developers don't pay much attention to the XPath queries they use. And then some complaining about XML performance. Of course, XML&amp;nbsp;means overhead but we're here not to&amp;nbsp;make it worse. For example, such convenient descendant-or-self axis specifier (AKA &amp;#8220;//&amp;#8221;)&amp;nbsp;can be&amp;nbsp;frequently&amp;nbsp;abused without realizing how much harm it can bring to high volume XML processing applicaitons. Say we have an XML message with simple structure like this:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;lt;Root&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Inventory1&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;item0&amp;gt;0&amp;lt;/item0&amp;gt;&lt;BR&gt;...&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;item499&amp;gt;499&amp;lt;/item499&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Inventory2&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;item500&amp;gt;500&amp;lt;/item500&amp;gt;&lt;BR&gt;...&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;item999&amp;gt;999&amp;lt;/item999&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Inventory2&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Inventory1&amp;gt;&lt;BR&gt;&amp;lt;/Root&amp;gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;(yeah, it looks strange, but some pretty wild schemas may be seen in enterprise integration scenarios)&lt;/P&gt;
&lt;P&gt;Suppose we want to parse item999 so the lazy query would be &amp;#8220;//item99&amp;#8221;. This will scan entire document tree&amp;nbsp;at all levels in search for the desired node. The optimal solution would be to narrow down query to &amp;#8220;/Root/Inventory1/Inventory2//item999&amp;#8221; given we have assurance that this&amp;nbsp;element will always be somewhere under Inventory2. Is it worth it? Well, on my desktop using .Net 2.0&amp;nbsp;with the test XML document above (1000 itemN elements) this yeilds almost&amp;nbsp;3.5 times performance gain. Real life gains can be&amp;nbsp;less or greater depending on schema, number of elements and their distribution.&amp;nbsp;The bottom line, performance losses&amp;nbsp;caused by&amp;nbsp;inefficient&amp;nbsp;XPath&amp;nbsp;can be critical for high throughput messaging solutions.&lt;/P&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=86569"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=86569" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/paulp/aggbug/86569.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Paul Petrov</dc:creator>
            <guid>http://geekswithblogs.net/paulp/archive/2006/07/28/86569.aspx</guid>
            <pubDate>Fri, 28 Jul 2006 23:05:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/paulp/comments/86569.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/paulp/archive/2006/07/28/86569.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/paulp/comments/commentRss/86569.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/paulp/services/trackbacks/86569.aspx</trackback:ping>
        </item>
    </channel>
</rss>