xsl-list
[Top] [All Lists]

Re: Passing DTD as systemID into StreamSource

2003-11-07 13:41:37
Pramodh Peddi wrote:
I am just passing the dtdURL, asking it to validate using the given dtdURL.

The problem is, the parameter is *not* the URL pointing to the DTD but the
URL for the *source* you are passing. It is used as base URL for resolving
URLs in the XML document.

The dtdURL is "http://servername:80/dir/SonyDAM.dtd";. The funky thing it is
doing is, it is resolving the name to be
"http://servername:80/dir/SonyDam.dtd";. I did not understand why it is doing
that.

I guess the DOCTYPE in the source is
 <!DOCTYPE whatever SYSTEM "SonyDam.dtd">
instead of
 <!DOCTYPE whatever SYSTEM "SonyDAM.dtd">

If what I am doing is wrong, is there any other way I can do this?

A more common approach is to write a custom entity resolver (or go to
 http://xml.apache.org/commons/components/resolver/index.html
and get James Clark's cataolg based resolver), and provide it to the parser,
roughly like
  XMLReader parser =
   SAXParserFactory.newInstance().newSAXParser().getXMLReader()
  parser.setEntityResolver(myEntityResolver);
  ...
  transformer.transform(new SAXSource(parser,new InputStream(...),...)


One more question reg'g dtd: If we have
<!DOCTYPE SONY_PRODUCT_METADATA SYSTEM "Metadata.dtd">

in the xml source, where should the Metadata.dtd be placed when the
transformation is done inside an application server? Where does it first
look into to find the dtds?

If the software can determine an absolute URL as the base URL, the DTD
system id is resolved against this base URL the usual way (should be in
the relevant RFCs). If the base URL can't be determined or is a relative
URL itself, a processor specific fallback is used. This is often assuming
the current working directory of the process as base URL, which is most
probably something you wont like to use in the case of an application
server. Other fallbacks, including throwing runtime exceptions, are not
unheard of.
Your best bets:
- always provide a proper absolute URL for any input
- use an EntityResolver and perhaps URIResolvers

J.Pietschmann



XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>