Querying XML in databases

Tom Dyson points out that XPath support for PostgreSQL is in the works. Here's the example he gives:

SELECT
article_id, xpath_string(article_xml,'\/beatles/\@beatle_id') AS beatle_id;
FROM
t_articles
WHERE
xpath_bool(article_xml,'/beatles/beatle[@alive="yes"]');


Meanwhile, over at John Merrells' weblog, you can try out SleepyCat XML DB -- more straightforwardly, in fact, than if you go in through the front door. I couldn't quite get it working on OS X, next time I'll go the Linux route.

Even as the XML query language debate [via Collaxa's Take] continues, it's clear that XPath is the foundation for querying XML documents stored in databases. Here's another example, from the Berkeley DB XML FAQ:

void DatingService::addProfile
(const std::string &username, DbXml::XmlDocument &profile)
{
XmlResults results
(profiles_.queryWithXPath(0,"/client[@username='"+username+"']"));
if(results.size()==0)
{
profiles_.putDocument(0,profile);
}
}

What's still unclear is how declarative updates will work. There are lots of approaches: updategrams, XUpdate, XQuery update. SQL wasn't built in a day, so it shouldn't be surprising that this stuff is taking a long time to cook.


Former URL: http://weblog.infoworld.com/udell/2003/03/17.html#a640