[jdom-interest] EntityResolver Problem

Norrman Per per.norrman at canovia.se
Fri Oct 4 04:58:26 PDT 2002


Hi,

why not make you remapped URI absolute: file:/x/y/z/lib/xhtml1-strict.dtd

/Per Norrman

-----Original Message-----
From: Cory C. Omand [mailto:Cory.Omand at Sun.com] 
Sent: Friday, October 04, 2002 2:51 AM
To: jdom-interest at jdom.org
Subject: [jdom-interest] EntityResolver Problem


Hello,

I am attempting to parse an XHTML file behind my company firewall.  As I 
cannot access the w3c website directly in order to resolve the DTD 
reference, I have created a custom EntityResolver class to remap the URI 
to a local filesystem path.  The problem is that the XHTML DTD contains 
ENTITY references which are causing problems during parsing.  The 
following code

            org.jdom.input.SAXBuilder builder = new 
org.jdom.input.SAXBuilder();
            builder.setEntityResolver(new StubResolver());
            org.jdom.Document doc;
            try {
                doc = builder.build(parseFile);
            } catch (org.jdom.JDOMException jde) {
                jde.printStackTrace();
                System.exit(1);
            }
            System.out.println("Successfully created a document from " + 
parseFile.getName());

Creates this stack trace when executed:

bash$ java -cp lib/jdom.jar:. SimpleParser index.xhtml
INFO: External Entity http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd 
remapped to ./lib/xhtml1-strict.dtd
org.jdom.JDOMException: Error on line 28: Relative URI "xhtml-lat1.ent"; 
can not be resolved without a base URI.
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:367)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:707)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:689)
        at SimpleParser.<init>(SimpleParser.java:20)
        at SimpleParser.main(SimpleParser.java:39)
Caused by: org.xml.sax.SAXParseException: Relative URI "xhtml-lat1.ent"; 
can not be resolved without a base URI.
        at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3182)
        at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3176)
        at org.apache.crimson.parser.Parser2.resolveURI(Parser2.java:2758)
        at 
org.apache.crimson.parser.Parser2.maybeExternalID(Parser2.java:2730)
        at 
org.apache.crimson.parser.Parser2.maybeEntityDecl(Parser2.java:2632)
        at 
org.apache.crimson.parser.Parser2.maybeMarkupDecl(Parser2.java:1210)
        at 
org.apache.crimson.parser.Parser2.externalParameterEntity(Parser2.java:2898)
        at 
org.apache.crimson.parser.Parser2.maybeDoctypeDecl(Parser2.java:1167)
        at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:489)
        at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
        at 
org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
        ... 4 more
Caused by: org.xml.sax.SAXParseException: Relative URI "xhtml-lat1.ent"; 
can not be resolved without a base URI.
        at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3182)
        at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3176)
        at org.apache.crimson.parser.Parser2.resolveURI(Parser2.java:2758)
        at 
org.apache.crimson.parser.Parser2.maybeExternalID(Parser2.java:2730)
        at 
org.apache.crimson.parser.Parser2.maybeEntityDecl(Parser2.java:2632)
        at 
org.apache.crimson.parser.Parser2.maybeMarkupDecl(Parser2.java:1210)
        at 
org.apache.crimson.parser.Parser2.externalParameterEntity(Parser2.java:2898)
        at 
org.apache.crimson.parser.Parser2.maybeDoctypeDecl(Parser2.java:1167)
        at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:489)
        at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
        at 
org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:707)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:689)
        at SimpleParser.<init>(SimpleParser.java:20)
        at SimpleParser.main(SimpleParser.java:39)
Caused by: org.xml.sax.SAXParseException: Relative URI "xhtml-lat1.ent"; 
can not be resolved without a base URI.
        at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3182)
        at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3176)
        at org.apache.crimson.parser.Parser2.resolveURI(Parser2.java:2758)
        at 
org.apache.crimson.parser.Parser2.maybeExternalID(Parser2.java:2730)
        at 
org.apache.crimson.parser.Parser2.maybeEntityDecl(Parser2.java:2632)
        at 
org.apache.crimson.parser.Parser2.maybeMarkupDecl(Parser2.java:1210)
        at 
org.apache.crimson.parser.Parser2.externalParameterEntity(Parser2.java:2898)
        at 
org.apache.crimson.parser.Parser2.maybeDoctypeDecl(Parser2.java:1167)
        at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:489)
        at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
        at 
org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:707)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:689)
        at SimpleParser.<init>(SimpleParser.java:20)
        at SimpleParser.main(SimpleParser.java:39)

All of the externally reference files (dtd and ent files) are in the 
./lib directory where the XHTML DTD lives.  Can anyone give me a hint as 
to why the SAX parser cannot find these .ent files, and/or how to 
resolve this problem?  I am using JDOM B8 + JDK 1.4.0.

Thanks in advance,
C.

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com
###########################################

This message has been scanned by F-Secure Anti-Virus for Microsoft Exchange.
For more information, connect to http://www.F-Secure.com/



More information about the jdom-interest mailing list