Archive

Posts Tagged ‘xml’

Querying XML with eXist

August 7th, 2009

Recently I needed to be able to be able to query a bunch of XML files using XQuery. I looked at some options like CouchDB but ultimately I needed a database of some sort that had native support for XQuery. While it looks like you can add on or hack in XQuery support to CouchDB, I preferred to keep things simple and went with eXist.

eXist allows you to store XML documents, with supporting DTDs and schemas, and access the collections using various mechanisms like REST or WebDAV. Once you have a number of XML documents in your repository, issuing an XQuery using the REST interface is pretty simple:

The above query will return a something like:

You can learn more about XQuery’s FLWOR structure here.

But eXist is more than just an XML store. By supporting XPath, XUpdate and XQuery Update, as well as custom extensions, eXist can be an application platform. I’m looking forward to working with XForms and Wicket in the future and I believe eXist will play heavily in that.

nick Entry , ,

Customizing JAXB’s Namespace Prefixes

November 21st, 2008

At a recent event in Denver, some of our integration partners complained about the namespace prefixes in the XML we generated. By default, JAXB creates simple prefixes like “ns1″, “ns2″ and so on. I’m not sure it matters unless you’re processing XML using some archaic means, but keeping partners happy is usually a good idea, so I turned to the JAXB API.

JAXB makes prefix customization pretty easy through the NamespacePrefixMapper class, found in the com.sun.xml.bind.marshaller package. The abstract class has one method to implement:

From here, it’s a simple matter of returning the prefix you want for a given namespace, then telling your JAXBContext about your implementation:

If you’re also using javax.xml.xpath.XPath, your NamespacePrefixMapper can also implement javax.xml.namespace.NamespaceContext, centralizing your namespace customization in a single class.

nick Entry , , , ,