[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

SAXParser stumbles over internal DTD declaration

  • From: Wim de Vries <w.vries@e...>
  • To: xml-dev@l...
  • Date: Thu, 10 May 2001 15:37:19 +0200

saxparser dtd
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 


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.