Five Practical XQuery Applications (cont'd)
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.
advertisement


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.

Previous Page: Application 4: Supply Chain Band Aid  
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 .
Srinivas Pandrangi is a software architect at Ipedo Inc. and a member of the W3C XML Query working group, where he is working on the standardization of XQuery. His recent articles have been published in XML Journal and on DevX. You can reach him .
Page 1: IntroductionPage 4: Application 3: Stock Analysis Automation
Page 2: Application 1: Log File IntelligencePage 5: Application 4: Supply Chain Band Aid
Page 3: Application 2: An Executive DashboardPage 6: Application 5: Trade Audit Server