[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Classpathx-xml] Unwanted SAXParseException

From: Ito Kazumitsu
Subject: [Classpathx-xml] Unwanted SAXParseException
Date: Sat, 18 Oct 2003 08:59:20 +0900
User-agent: EMH/1.10.0 SEMI/1.13.7 (Awazu) FLIM/1.13.2 (Kasanui) Emacs/21.2 (i386-unknown-freebsd4.7) MULE/5.0 (SAKAKI)


I found a case where GNU JAXP throws unwanted SAXParseExceptions.
The test case is attached below.  When using Sun's JAXP or
Xerces,  such exceptions are not thrown.

Also attached is my suggested patch,  which I am going to
apply to the source imported to Kaffe.

bash-2.05b$ cat 
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;

public class TestEntityResolver {

    public static void main(String[] args) throws Exception {
        String url = (new File(args[0])).toURL().toString();
        SAXParserFactory factory = SAXParserFactory.newInstance();
        XMLReader xr = factory.newSAXParser().getXMLReader();
        xr.setErrorHandler(new MyHandler());
        xr.setEntityResolver(new MyResolver());
        try {
        catch (SAXParseException e) {

private static class MyResolver implements EntityResolver {
  public InputSource resolveEntity (String publicId, String systemId) {
      try {
          return new InputSource((new URL(systemId)).openStream());
      catch (Exception e) {
          return null;

private static class MyHandler extends DefaultHandler {
  public void warning(SAXParseException e) {


bash-2.05b$ cat test.xml 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Test PUBLIC "" "test.dtd">
<Test />
bash-2.05b$ cat test.dtd 
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT Test (A)* >
bash-2.05b$ java TestEntityResolver test.xml 
org.xml.sax.SAXParseException: URI was not reported to parser for entity [dtd]
org.xml.sax.SAXParseException: missing system ID, using test.dtd

And here is my patch:
bash-2.05b$ diff -u gnu/xml/aelfred2/ 
--- gnu/xml/aelfred2/        Sat Oct 18 08:37:57 2003
+++ gnu/xml/aelfred2/     Sat Oct 18 08:43:42 2003
@@ -596,6 +596,8 @@
                        in.getSystemId ());
            if (source == null)
                source = in;
+           else if (source.getSystemId () == null)
+               source.setSystemId (in.getSystemId ());
        startExternalEntity (name, source.getSystemId (), true);
        return source;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]