Avoid unnecessary sorting
XQuery is a language where most of our work revolves around parsing XML and getting data out of XML using XPath. This practice emphasize the need to avoiding unnecessary sorting and path expression which doesn’t seem an overhead at once but it build on quite fast when implementing large XQuery modules.
Lets look at a common example:
In the above example, you see we are retrieving two values on the XML Name and Store. Now what is happening in XQuery engine is that, it will read from root element from sampleXML and fetch the two element values and then output the same. This is an overload.
Now to better look at an alternative which reduces it. XQuery creates a node structure from XML so once you have fetch till Game element, we don’t need to do it again.
Below is how this can be done.
Output remains same but it surely is a good practice to bring it and will help to reduce XQuery execution for large XML and applications.
Hope you like this tip!
Watch this space for more.