[DAS2] Working with xml:base in Java?

Helt,Gregg Gregg_Helt at affymetrix.com
Wed Feb 8 08:36:01 UTC 2006

	I've been mucking around trying to find an answer to my own
question about ways to easily handle xml:base in Java.  And I think the
answer if I want to continue to use DOM ends up being "code it
yourself".  But it took a while to get to that answer.  I'm writing down
these notes so I can refer back to them next time if the issues I
encountered come up again.  But I figured I might as well post in case
other DAS/2 implementers have similar problems.

	So the standard Java 1.5 distribution includes the
org.xml.dom.Node interface, which conveniently enough has a getBaseURI()
method that should do exactly what I want -- for any node in an XML
document, give me the resolved base URI for that node (regardless of how
complex a combination of xml:base attributes are used in the path to
that node).  Which I can then combine with whatever id attribute I'm
interested in (via Java networking classes) to get the full URI.
	But I need to guarantee compatibility with Java 1.4, so I can't
rely on 1.5.  Java 1.4 has a previous version of org.xml.dom.Node, but
with no getBaseURI() method.  Turns out this is because the 1.5 Node
interface complies with DOM-level3 spec (includes XML Base support) but
the 1.4 Node interface only supports DOM-level2 spec (no XML Base
support).  Okay, but I can download the Xerces2 distribution, which is a
Java library that also has a full implementation of DOM-level3.  So I
get that set up, add some calls to node.getBaseURI() to my code, and it
compiles fine.  But when I run the program I get an ugly
java.lang.NoSuchMethodError.  I dig around on the web and find the
problem is a class/package namespace collision -- both Xerces2 and the
builtin java libraries have a class named org.xml.dom.Node, but of
course they're different.  And replacing built-in java classes is not
normally allowed, so when the program is actually run and classes are
loaded the builtin Node class wins (the one w/o the getBaseURI()
method).  It would have been nice if they mentioned this in the JDK
Compatibility section of the Xerces2 FAQ...
	But there is some discussion of solutions to this problem on the
Xerces mailing list. There is actually a way to replace builtin java
packages via an "Endorsed Standards Override Mechanism", if they're on
the list of endorsed standards, which org.w3c.dom is.  This involves
putting the replacement package in an endorsed directory and setting a
system property to direct the JVM to look there for replacement
packages. But... whatever solution I use has to work with Java WebStart.
I can't find _any_ info on whether the package override mechanism works
with WebStart.  And even if it does work for some WebStart
implementations, I'd be wary of assuming it works for others -- it seems
like one of those things IT folks on the user end might get concerned
about.  I've also found other solutions to the package name clash, but
none that seems compatible with WebStart.

	So it looks like, considering my other constraints, if I want to
stick with DOM I'll need to code xml:base handling myself.  Looking at
the source code for Xerces2, doesn't look too hard.  Except... damn, the
getBaseURI() method implementation is actually commented in the Xerces
code as "Experimental".  Looking closer... um, I think it actually
doesn't implement the spec correctly.  Grr... 

To summarize, when it's time for my status report tomorrow, I think it's
best if I just remain silent.


P.S. I suspect the answer for SAX will be similar.
P.P.S. XOM (http://www.xom.nu/) is starting to look pretty good, but I
may just be hallucinating at this point...
> From: das2-bounces at portal.open-bio.org
[mailto:das2-bounces at portal.open-
> bio.org] On Behalf Of Helt,Gregg
> Sent: Tuesday, February 07, 2006 11:01 AM
> To: Thomas Down
> Cc: DAS/2
> Subject: [DAS2] Working with xml:base in Java?
> 	Thomas, I'm wondering what toolkits you're using for binding XML
> to Java objects?  And particularly how you are dealing with resolving
> URIs when xml:base is used.  So far I've mostly used various
> implementations of SAX and DOM -- I've found some reports of builtin
> xml:base support in Xerces SAX/DOM, but it's still unclear.
> 	I've been avoiding the issue up till now.  It won't be too hard
> to implement URI resolution relative to xml:base, but I thought I'd
> check around first and see if there's automated support of this in
> toolkit.
> 	Thanks,
> 	Gregg
> _______________________________________________
> DAS2 mailing list
> DAS2 at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/das2

More information about the DAS2 mailing list