[xquery-talk] doc() function failing to load DTD

Michael Ludwig mlu at as-guides.com
Wed Apr 15 11:48:44 PDT 2009

George Feinberg schrieb:
> Michael,
> Your issue is somewhat product-specific.  In this case you are using
> Berkeley DB XML and it's dbxml shell program for testing.

Hi George :-) Yes, exactly, dbxml shell for testing.

> The problem is not the URI for the file but the file's reference to
> the DTD.  BDB XML uses Xerces-C for parsing/validation and
> by default Xerces-C will look in the current directory for DTDs
> referenced by a relative pathname (e.g. "Sender.dtd").  If you
> change that to an absolute pathname or file: URI your query
> will succeed.

Yes, that works.

> In BDB XML you have another option if you write it into your
> program (vs using the dbxml shell).  You can implement XmlResolver
> and resolve entities such as DTDs yourself.

That works fine, too. I took a look at the C++ sample program contained
in the Berkeley DB XML distribution and implemented something similar to
set a base URI for external entities, which I'm appending in case anyone
is looking for it.


Michael Ludwig

public final class TestResolver extends XmlResolver {
   private String dir;

   public void setDirectory(String dir) {
     if (dir.endsWith("/"))
       this.dir = dir;
       this.dir = dir + "/";

   public XmlInputStream resolveEntity(
       XmlTransaction txn, XmlManager mgr,
       String systemId, String publicId) throws XmlException
     String path = dir + systemId;
     System.err.format("RESOLVER: %s -> %s%n", systemId, path);
     return mgr.createLocalFileInputStream(path);


   TestResolver resolver = new TestResolver();
   resolver.setDirectory( "C:/MILU/dev");

More information about the talk mailing list