YOUR FEEDBACK
John Portnov wrote: This code does not work for me. I created a new website and a C# console applic...
AJAXWorld RIA Conference
$300 Savings Expire August 22
Register Today and SAVE!


2008 East
DIAMOND SPONSOR:
Data Direct
Frontiers in Data Access: The Coming Wave in Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
Intel
Virtualization – Path to Predictive Enterprise
Green Hills
IT Security in a Hostile World
JBoss / freedom oss
Practical SOA Approach
GOLD SPONSORS:
Software AG
The Art & Science of SOA: How Governance Enables Adoption
PlateSpin
Effective Planning for Virtual Infrastructure Growth
Fujitsu
Automated Business Process Discovery & Virtualization Service
Ceedo
Workspace Virtualization
Click For 2007 West
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
TODAY'S TOP SOA & WEBSERVICES LINKS


Use a Native XML Database for Your XML Data
Deciding when an XQuery-based native XML database is better than an SQL database


dbxml> putDocument "" "for $i in (0 to 2999) return
<part number='{$i}'>
<description>Description of {$i}</description><category>
{$i mod 10}</category>
{if (($i mod 10) = 0) then <parent-part>{$i mod 3}</
parent-part> else ''}</part>" q
A single output line for each document will be printed as confirmation. The generated content looks like this:

<part number="999">
<description>Description of 999</description>
<category>9</category>
</part>
Every 10th document of the 3,000 generated will look something like this:

<part number="990">
<description>Description of 990</description>
<category>0</category>
<parent-part>0</parent-part>
</part>
The numbers vary to allow more complex queries later. Let's dive in. First, let's find all part records that contain a parent-part, or "from the container named parts select all part elements that also contain a parent-part as a direct child of that element" (see Listing 3).

If you're only interested in the parent-part element, try the following:


dbxml> query collection("parts")/part/parent-part
300 objects returned for eager expression 'collection
("parts")/part/parent-part'
dbxml> print
<parent-part>0</parent-part>
<parent-part>0</parent-part>
...
<parent-part>2</parent-part>
<parent-part>2</parent-part>
Or if you simply need the value of the parent-part element, execute this query:

dbxml> query collection("parts")/part/parent-part/text()
300 objects returned for eager expression 'collection("parts")/
part/parent-part/text()'
dbxml> print
0
0
...
2
2
To find documents without parent-part elements, see Listing 4. To find two specific parts by part number try the following:

dbxml> query 'collection("parts")/part[@number =
1070 or @number = 1032]'
2 objects returned for eager expression 'collection("parts")/
part[@number = 1070 or @number = 1032]'
dbxml> print
<part number="1070"><description>Description of 1070</
description><category>0</category><parent-part>2</
parent-part></part>
<part number="1032"><description>Description of 1032</
description><category>2</category></part>
Listing 5 shows it's equally simple to find a range of parts.

Now let's explore the effect of indices. Your query times may differ as your machine is likely different from ours, but the improvement should be somewhat comparable.


dbxml> setVerbose 1
dbxml> query collection("parts")/part[parent-part]
Query - Finished eager query execution,
time taken = 2399.15ms
300 objects returned for eager expression 'collection("parts")/
part[parent-part]'
Spending 2.4 seconds to examine 3,000 documents and find the matching 300 isn't bad for a file system, but this is a database engine. Indices should improve performance. Berkeley DB XML indices are specified in four parts: path type, node type, key type, and uniqueness. In this case we need to index the node elements to determine if something is present or not, and we won't expect this pattern to be unique. Let's try the query again, but this time with an index to optimize searches for documents containing a parent-part element, a "node-element-presence-none" index.

dbxml> addIndex "" parent-part node-element-presence-none
Adding index type: node-element-presence-none to node:
{}:parent-part
dbxml> query collection("parts")/part[parent-part]
Query - Finished eager query execution,
time taken = 176.925ms
300 objects returned for eager expression 'collection("parts")/
part[parent-part]'
From 2.4 seconds to just under 1/5th of a second seems like a worthwhile improvement. Let's try another query.

dbxml> query 'collection("parts")/part[parent-part = 1]'
Query - Finished eager query execution,
time taken = 215.387ms
100 objects returned for eager expression 'collection("parts")/
part[parent-part = 1]'
The query executed in just over 1/5th of a second without an index. Since this query searches for a specific node's number, a "node-element-equality-decimal" index should help speed things up.

dbxml> addIndex "" parent-part node-element-equality-decimal
Adding index type: node-element-equality-decimal to node: {}:parent-part
dbxml> query 'collection("parts")/part[parent-part = 1]'
Query - Finished eager query execution,
time taken = 79.973ms
100 objects returned for eager expression 'collection("parts")/
part[parent-part = 1]'
Wonderful, query execution time has been reduced by more than half, to under 1/10th of a second by adding that second index. Let's try one final example - the range query we tried earlier.

dbxml> query 'collection("parts")/part[@number >
100 and @number < 105]'
Query - Finished eager query execution,
time taken = 5917.83ms
4 objects returned for eager expression 'collection("parts")/
part[@number > 100 and @number < 105]'
Six seconds is an eternity in database terms, so let's create another and try again.

dbxml> addIndex "" number node-attribute-equality-decimal
Adding index type: node-attribute-equality-decimal to node:
{}:number
dbxml> query 'collection("parts")/part[@number >
100 and @number < 105]'
Query - Finished eager query execution,
time taken = 85.99ms
4 objects returned for eager expression 'collection("parts")/
part[@number > 100 and @number < 105]'
The index reduced the query time back down to less than a 1/10th of a second.

Conclusion
Pick the right tool for the job. An XML-centric design will benefit from a native XML database. Managing XML content can be easy, predictable, flexible, secure, and fast. Save yourself the headaches, time, and expense of solutions that are less suited to the task.

About Gregory Burd
Gregory Burd is the Product Manager for Sleepycat Software, now a part of Oracle. Prior to Sleepycat, he was on the business team at KnowNow, a Kleiner Perkins startup in the San Francisco Bay Area. He has many years of software development and product leadership within companies such as JavaSoft, a division of Sun Microsystems, Marble Associates, a consulting company, and NeXT Computer, now part of Apple Computer.

About Kimbro Staken
Kimbro Staken is an independent consultant, author, and open source developer specializing in technologies for XML data management. He is one of the primary developers of the dbXML Core Open Source native XML database and a cofounder of the XML:DB Initiative.

XML JOURNAL LATEST STORIES . . .
ISO said Friday that the appeals made by Brazil, India, South Africa and Venezuela protesting the standardization of Microsoft’s Office Open XML (OOXML) file format hadn’t gone anywhere – it was unclear whether any of them had any standing anyway – but since they “failed to g...
Red Hat CTO Brian Stevens, Citrix CTO Simon Crosby, Egenera CTO Pete Manca, Allen Stewart, Group Manager, Windows Virtualization at Microsoft, and Brian Duckering, Sr. Director of Products and Alliances at Symantec were the top industry executives who joined Jeremy Geelan in the 4th Fl...
Two of the biggest launches in Rich Internet Application history took place in 2007/2008 when Adobe launched AIR 1.0 in February '08 and Microsoft launched Silverlight (September '07). At the 6th International AJAXWorld RIA Conference & Expo in October SYS-CON Events is delighted to be...
Since its inception, XML has been criticized for the overhead it introduces into the enterprise infrastructure. Business data encoded in XML takes five to 10 times more bandwidth to transmit in the network and proportionally more disk space to store.
Vordel unveiled version 5.1 of its XML network infrastructure products, to accelerate, manage and protect XML applications. Vordel 5.1 addresses the need for lifecycle management of policy across the SOA. By combining the central management of SOA policies with distributed enforcement ...
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON FEATURED WHITEPAPERS


ADS BY GOOGLE
BREAKING XML NEWS
Avineon, Inc. (http://www.avineon.com), a successful provider of IT, geospatial, engineering and pro...