Dear Francis,
(Paraphrasing from a previous answer on essentially the same question:)
The problem is that since using an Input"Stream"Source you have provided
no way for the parser to determine where to resolve paths to the
resource you are parsing, it only has this stream of bytes, no origin.
So, if you want to use an InputSource, you should set the system id on
the
inputsource:
is.setSystemId("../testresolve.xml");
so Xerces knows where to look for the DTD relative to.
Kind regards,
--Sander.
> -----Original Message-----
> From: Francis Upton [mailto:[EMAIL PROTECTED]
> Sent: 06 November, 2003 3:37 AM
> To: [EMAIL PROTECTED]
> Subject: problem resolving SYSTEM entity to current directory
>
>
> Using Xerces-J version 2.5.0, I am running into a problem
> where a relative
> SYSTEM entity reference seems to be attempted to be resolved
> to the current
> directory (and fails), rather than to the location of the
> document (as
> specified in the XML specification).
>
> I have the following XML File:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE Guideline SYSTEM 'testresolve.dtd'>
> <x/>
>
> In the same directory is the file 'testresolve.dtd'.
>
> From a different directory, I run this code:
>
> import java.io.*;
>
> import org.xml.sax.*;
> import org.xml.sax.helpers.*;
>
> public class test
> {
>
> protected static final String DEFAULT_PARSER_NAME =
> "org.apache.xerces.parsers.SAXParser";
>
>
> public static void main(String[] args)
> {
> try
> {
> InputSource is =
> new InputSource
> (new BufferedInputStream
> (new FileInputStream("../testresolve.xml")));
>
> XMLReader xmlReader = XMLReaderFactory.
> createXMLReader(DEFAULT_PARSER_NAME);
> xmlReader.parse(is);
> }
> catch (Exception ex)
> {
> ex.printStackTrace();
> }
> }
>
> }
>
>
> And when I run it, I get this result:
>
> /temp/trans/x> java test
> java.io.FileNotFoundException:
> c:\temp\trans\x\testresolve.dtd (The system
> cannot find the file spec
> ified)
> at java.io.FileInputStream.open(Native Method)
> at java.io.FileInputStream.<init>(FileInputStream.java:106)
> at java.io.FileInputStream.<init>(FileInputStream.java:66)
> at
> sun.net.www.protocol.file.FileURLConnection.connect(FileURLCon
> nection.java:69)
> at
> sun.net.www.protocol.file.FileURLConnection.getInputStream(Fil
> eURLConnection.java:156)
> at java.net.URL.openStream(URL.java:913)
> at
> org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unk
> nown Source)
> at
> org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
> at
> org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown
> Source)
> at
> org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.di
> spatch(Unknown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocu
> ment(Unknown
> Source)
> at
> org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
> at
> org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
> at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
> at
> org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
> at test.main(test.java:25)
>
> However, if I copy the file 'testresolve.dtd' to the current
> directory, I
> get this result (which is what I expect):
>
> /temp/trans/x> cp ../testresolve.dtd .
> /temp/trans/x> java test
> /temp/trans/x>
>
> Am I doing something wrong, or is this a bug?
>
> Could this be related (or the same as) bug 11441?
>
> Thanks,
>
> Francis
>
>
> Francis Upton
> nogoop software
> ActiveX/COM Inspector
> .NET Component Inspector
> Java HTTP Client
> www.nogoop.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]