RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Five Practical XQuery Applications : Page 6

XQuery is still a relatively new and unfamiliar XML-based language, but it offers many possibilities for simplifying tasks that today are difficult or tedious. These five practical scenarios should give you ideas for leveraging XQuery in your own applications.

Application 5: Trade Audit Server
Several industries require that trade documents be saved in their original form. Examples range from EBT in the energy industry to XBRL for retail banks. These inescapable regulations typically require an IT department to set up a custom environment outside the trading application. Companies often want to hold on to these documents in case disputes arise—showing an actual copy of a trade is proof that it happened. This is often referred to as non-repudiation—no one can repudiate the trade if you have a copy of the trade message or document.

The problem is that transactions add up. Trying to find a trade document days or weeks after the fact can be a challenge. A good solution would be a search application that can mine through hundreds or thousands of trades to find a specific trade. With XQuery, you can do much better than a simple search. You can look for a set of conditions—say, a certain trading partner, a time range, and a combination of words in the instructions (like "trade" and "at market").

Anyone with only modest knowledge of XML and SQL can learn XQuery relatively quickly.
In this scenario, a trading firm keeps all the trading documents in a collection of documents named "tradelogs". We need a query which, for any given trader, finds all the trades that trader executed after hours where the total trade price is less than $15,000, and where the trade instructions contain a specific keyword or phrase.

The following query uses the $trader parameter and the $keyword parameter to retrieve all the matching trades.

   for $trade in collection("tradelogs")//trade
   where $trade/traderName = $trader and
      $trade/executionTime = "afterhours" and
      $trade/tradePrice < 15000 and
      (some $instruction in $trade//instruction satisfies
         (contains($instruction, $keyword)))
   return $trade
As you can see from these scenarios, XQuery can help solve practical problems faced by IT departments. However, these scenarios only scratch the surface of XQuery's capabilities. Anyone with only modest knowledge of XML and SQL can learn XQuery relatively quickly. Because XQuery works against many different data types and formats, it's tremendously useful whether you are searching a file system, a relational database, a document management system, a Web service, or all of these simultaneously. When you top that off with its ability to integrate and transform results, XQuery truly embodies the next generation of query languages.

Tim Matthews is co-founder of Ipedo, Inc. He has extensive experience in high tech sales, marketing, and engineering. Prior to co-founding Ipedo in 2000, he was Director of Product Marketing at RSA Security (Nasdaq: RSAS), where he oversaw a line of developer security products and a line of security infrastructure servers. Previously, Tim worked in international sales and business development at Digital Equipment Corporation in Tokyo, Japan and Irvine, California. Email Tim .
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date