[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SAXParser stumbles over internal DTD declaration
- From: Wim de Vries <w.vries@elsevier.nl>
- To: xml-dev@lists.xml.org
- Date: Thu, 10 May 2001 15:37:19 +0200
Hi,
I'm using the SAXparser and it validates OK against an external dtd, but
when the XML doc also has some internal dtd declarations I get the folowing
error:
-------------
Exception in thread "main" java.lang.NullPointerException
at org.apache.xerces.frameworkXMLParser.parse.(XMLParser.java:965)
at MySAXApp.main(MySAXApp.java, Compiled code)
-------------
Does someone knows what's going wrong? See code below.
SAXParser fails on:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE personnel SYSTEM "personal.dtd" [<!ENTITY gr1 SYSTEM "gr1" NDATA
image>]>
<personnel>.........
SAXparser succeeds on:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE personnel SYSTEM "personal.dtd">
<personnel>.........
Thanks.
************************************
import java.io.FileReader;
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.SAXParseException;
public class MySAXApp extends DefaultHandler
{
public static void main (String args[])
throws Exception
{ //XMLReader interface gets filled with the SAXParser
XMLReader xr = new org.apache.xerces.parsers.SAXParser();
//XMLReader used to be Parser
try {
xr.setFeature("http://xml.org/sax/features/validation",
true);
} catch (SAXException e) {
System.out.println("error in setting up parser
(XMLReader) feature");
}
try {
xr.setFeature("http://apache.org/xml/features/validation/dynamic", true);
} catch (SAXException e) {
System.out.println("error in setting up parser
(XMLReader) feature");
}
MySAXApp handler = new MySAXApp();
xr.setContentHandler(handler); //handler (this) shall receive
notifications of events
xr.setErrorHandler(handler);
xr.setDTDHandler(handler);
// Parse each file provided on the
// command line.
for (int i = 0; i < args.length; i++) {
FileReader r = new FileReader(args[i]);
xr.parse(new InputSource(r));
}
}
public MySAXApp ()
{
super();
}
public void startDocument ()
{
System.out.println("Start document");
}
public void endDocument ()
{
System.out.println("End document");
}
public void error(SAXParseException exception)
{
int LineNumber = exception.getLineNumber();
String ErrorString = exception.getMessage();
System.out.print("Stop feeding me invalid docs, you stupid
idiot: ");
System.out.print(ErrorString);
System.out.println(LineNumber);
}
public void fatalError(SAXParseException exception)
{
System.out.println("Fatal error");
}
public void warning(SAXParseException exception)
{
System.out.println("Warning");
}
public void endDTD()
{
System.out.println("enddtd");
}
public void startDTD(org.apache.xerces.utils.QName rootElement,
int publicId,
int systemId)
{System.out.println(">>>>>>>>>>");
System.out.println("rootElement");
}
}
****************************
With kind regards,
W(im) S. de Vries LL M
Information Structure Technologist
Electronic Production Department
Elsevier Science NL
tel. (+31) 20 4852733
fax (+31) 20 4852812
Sara Burgerhartstraat 25
1055 KV Amsterdam
The Netherlands