What with the holidays, and actual coding work, we’ve not crammed in to many posts for GenXDM lately. Time to fix that.
We’ve made a critical improvement (well, in the source, we’ve not done a release with it yet). Our original drop included a mutation API. We added this API to facilitate the conversion of existing XML tools that actually need to mutate existing XML trees. When we added the mutation APIs, we mirrored the functionality on what we were trying to replace: DOM. Among the unfortunately aspects, this gave us bug 16, that of baking a notion of “owner” into the mutable API.
A key trouble is that DOM conflates the “root” of a document with that of a “factory” for new elements. For all other XML tree APIs we’ve looked at, the APIs separate these two concepts. GenXDM already separated these two notions by introducing a “NodeFactory”, but that still required the use of an “owner” parameter. What to do?
XQuery Update Facility
Along our journey, we noticed XQuery Update Facility (XQUF), and consequently filed bug 19. We brought together the two bugs – the annoying DOM notion of “ownership” and our failure to follow the XQUF APIs. Fortunately, the XQUF APIs don’t have a notion of ownership, so perhaps we could kill two birds with one stone. We converted our mutable API to follow the pattern of XQUF. To prove it out, we also converted the one project that extensively uses the mutable APIs – XML Security. This ended up being a fair chunk of work, in part because there was no way to incrementally port XML Security to the new APIs, the whole library had to be converted all at once. (I’m using the combination of all of these changes plus holidays and such as part of my lame excuse for not posting more frequently.)
Very much like with the core GenXDM APIs, we’re not able to exactly follow the XQUF specification. Notably, XQUF has a notion of pending changes – all the APIs we have make immediate changes. This means that some of the methods, like “mergeUpdates”, and “applyUpdates” don’t make sense, and “propogateNamespaces” sort of makes sense, but we added “insertNamespace” instead. For the APIs that do make sense, we’ve done our best to follow XQUF.
For now, we’re thinking that a notion of pending changes will have to wait until we see a need for it, and then we can make it a part of interfaces that extend the ones we just built.
Overall, I’m happy with the changes, because it actually simplified some of the XML Security code changes. In places where we needed to pass along an instance of “NodeFactory”, an “owner”, and the node to be updated, we now only need to pass along the “NodeFactory” and the node to be updated. Of course, this implies that NodeFactory actually has state, and can only be used with a single DOM Document (if that’s your underlying model), but that’s pretty easy to deal with.
Conclusion
Our mutable API now has the benefit of actually being more closely tied to the XQuery standard that we’re trying to follow. Also simplified some of the code that actually mutates XML trees. Overall, a significant improvement.