tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <Craig.McClana...@eng.sun.com>
Subject Re: XML, DTD, Tomcat
Date Wed, 01 Nov 2000 01:21:59 GMT
Alex Tang wrote:

> Hi folks.
>
> I've got a servlet (actually a couple) that are doing some XML parsing
> (Mainly SAX, some DOM).
>
> The only problem I seem to be having is that when if I have a XML file
> that looks like this:
>
>      <?xml version="1.0" encoding="UTF-8"?>
>      <!DOCTYPE taglist SYSTEM "taglist.dtd">
>

What an XML parser does with this is really a question for your parser provider -- it's not
really a Tomcat issue.  I would imagine that it is being resolved relative to the current
working directory where you started Tomcat.

>
> Tomcat looks for the DTD file in the TOMCAT_HOME/bin directory.   the
> XML and DTD files are in my WEB-INF/classes part of my class path.
>
> >From what I understand of XML, using the
>
>      <!DOCTYPE ... SYSTEM "file.dtd">
>
> where the dtd file is given as a URI with no path, the parser should
> look for the DTD file in the same directory as the XML file.
>
> It's probably something stupid on my part.  I'm creating the InputSource
> using an input stream which I instantiate using "getResourceAsStream()",
> (which is probably where I'm going wrong).
>
>      InputStream ist = FormattedTextWidgetStub.class.getResourceAsStream ( ATTR_TAGFILE
);
>
>      InputSource iso = new InputSource ( ist );
>
>      parser.parse ( iso );
>
> Is there a better way to get the InputSource?   or is there any other
> way i can get tomcat to look for my DTD file in the same directory as my
> XML file (considering that I must keep my XML and DTD files in my
> classpath (under the WEB-INF/classes directory somewhere)?
>

While this is an appropriate way to get resources in a web application, note that doing so
gives the parser no clue where the input stream is coming from.

You might try getting a File reference to the input file, and passing that to your parse
method instead.  Alternatively, there is a mechanism in most parsers to register a separate
input source for a DTD (keyed by the public identifier).  Tomcat uses this approach, for
example, to register its local copies of the DTD for web.xml files, so that it doesn't need
to
go across the network every time.

>
> thanks very much.
>
> ...alex...

Craig McClanahan



Mime
View raw message