Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Five Practical XQuery Applications : Page 3

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.


advertisement
Application 2: An Executive Dashboard
Keeping tabs on a company's performance is at the top of the priority list for executives these days . That's why so-called "executive dashboards" are becoming so popular. Building an executive dashboard generally involves collecting real-time data from multiple sources and displaying that data in a Web portal, often in summary or graphic form.

But executive dashboard applications can make you crazy. You no sooner finish building the dashboard exactly as the clients want it than they want to add two more sources and completely change the layout. Recoding all those JSPs or ASPs can be tedious, but that's what the clients expect.

Rather than recoding each time, consider writing it all in XQuery That way you can add another data source (a query from a relational table or a snippet from a news feed) and change the layout in a much easier and more flexible way.

In this scenario, the apparel chain Wearhouse Inc. has a product catalog maintained in XML, but a sales database maintained in DB2. You are charged with building some custom reporting applications. You have just discovered the power of XQuery, so you decide to use an XML server capable of data integration to build these reports. Here's a sample query you might write that combines information from both the XML and DB2 data sources:

<sales> { for $product in document("products.xml")/products/product, $sales in view("db2/sales_view")/sales/product where $product/productId = $sales/productId return <product id="{$product/productId}"> {$product/productName, $product/productSpec, $sales/mrq, $sales/ytd, $sales/margin} </product> } </sales>

Now suppose that two months after you deploy your reporting application, Wearhouse Inc. acquires Caribbean Sunwear, a casual apparel business. Suddenly your reports need to include sales information for Caribbean Sunwear. But that information isn't in either XML or DB2, it's in a SQL Server database. You are in luck—your decision to use XQuery will spare you weeks of painful work integrating another data source into your application. All you need to do is define another view over the SQL Server database and modify your query to include that view. Doing that might take less than 20 minutes. Here's the altered query.

<sales> { for $product in document("products.xml")/products/product, $sales in (view("db2/sales_view")/sales/product, view("sqlserver/sales_view")/sales/product) where $product/@productId = $sales/productId return <product id="{$product/@productId}"> {$product/productName, $product/productSpec, $sales/mrq, $sales/ytd, $sales/margin} </product> } </sales>

The altered query includes the new SQL Server view and integrates the sales information from the newly acquired company into the executive dashboard sales report.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap