djspiewak/anti-xml — Issue #78: Improve support for URI parts in namespaces
Author: trygvis
Created: 2011-12-23 13:53:48+00:00
State: open

I've been trying to use anti-xml to parse and generate some XML documents that use some elements from the atom namespace [1]. My code uses our own private namespace, but in the documents it is bound to the default namespace. An example XML looks like this:

I've run into two issues with this.

The first is that the conversions drop the namespace entirely (see [2]). I've fixed this so that it's more in line with the existing API.

The second issue I see now is that the entire API is oriented around the "prefix" parts instead of the namespace part. When I'm converting the XML to my Profile object I don't care about the prefix, I just want the elements named "link" inside the Atom namespace. Right now I'll have to do this by hand.

I would like to adjust the API so that it's more in line with java.xml.QName and W3's definition, see [3] and [4]. The "prefix" is not a part of the qualified name of an element and really not very interesting when it comes to matching on objects.

I'm hoping to be able to write something like this:

def atomLinks(e: Elem) = (e / (Namespaces.atom -> "link"))

Does this make sense? I really like anti-xml and we're using it for most of our XML stuff now but this came up as an issue the other day and I don't see a way to fix it without changing anti-xml.

I've implemented my ideas under my own repository, [5]. I'm not entirely satisfied with the current solution but it shows what I want to achieve. All the existing tests passes and I've added some more too.

[1]: http://www.w3.org/2005/Atom
[2]: https://github.com/djspiewak/anti-xml/blob/5e5bd3fd95aba203d435c2266283ec6fc2296a7d/src/main/scala/com/codecommit/antixml/conversion.scala#L128
[3]: http://docs.oracle.com/javase/6/docs/api/javax/xml/namespace/QName.html
[4]: http://www.w3.org/TR/xmlschema-2/#QName
[5]: https://github.com/trygvis/anti-xml