You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Bill Lynch <bi...@coolservlets.com> on 2001/01/04 18:51:54 UTC
Loading DTD
All,
I'm using xerces to parse an XML file located in a Jar file. I also include
the dtd in the jar file but i get a parsing exception each time because
xerces can't find the dtd (which i reference as SYSTEM).
I see 2 possible solutions:
1) load the dtd as PUBLIC
2) include the DTD as part of my XML file
however, I'd like to keep the xml and dtd files seperate in the jar file --
how can i reference the dtd correctly?
Here's the DTD include (in jive_data.xml):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Jive SYSTEM "jive.dtd">
...
(BTW, is this the correct list for this type of question? i didn't see a
xerces-j-user list.)
Thanks in advance,
--Bill
-------------------------------------------------------
4charity.com blynch@4charity.com
CoolServlets.com bill@coolservlets.com
Re: Loading DTD
Posted by Christopher Lambrou <Ch...@msdw.com>.
Bill,
you may use the EntityResolver class to specify the DTD in flight.
This can also help you cache the DTD in memory, which we have found to
speed things up by 10 fold.
Steps:
1. Open the DTD as a regular file and create an org.xml.sax.InputSource object from it
2. Setup an class that implements EntityResolver. In that class, method resolveEntity is
called whenever the parser is looking for your DTD. Change it right then to the cached
org.xml.sax.InputSource (from #1)
public InputSource resolveEntity (String publicId, String systemId) {
return myCachedInputSource;
}
You will have to register your EntityResolver before you parse your XML doc, ie:
MyDTDResolver entityResolver = new MyDTDResolver();
m_parser = new DOMParser();
m_parser.setEntityResolver(entityResolver);
HTH
--
Christopher Lambrou
Morgan Stanley Dean Witter & Co.
Phone: (212) 762-2385
Fax: (212) 762-1007
Chris.Lambrou@msdw.com
Bill Lynch wrote:
> All,
>
> I'm using xerces to parse an XML file located in a Jar file. I also include
> the dtd in the jar file but i get a parsing exception each time because
> xerces can't find the dtd (which i reference as SYSTEM).
>
> I see 2 possible solutions:
> 1) load the dtd as PUBLIC
> 2) include the DTD as part of my XML file
>
> however, I'd like to keep the xml and dtd files seperate in the jar file --
> how can i reference the dtd correctly?
>
> Here's the DTD include (in jive_data.xml):
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE Jive SYSTEM "jive.dtd">
> ...
>
> (BTW, is this the correct list for this type of question? i didn't see a
> xerces-j-user list.)
>
> Thanks in advance,
> --Bill
>
> -------------------------------------------------------
> 4charity.com blynch@4charity.com
> CoolServlets.com bill@coolservlets.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org