You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Brad O'Hearne <ca...@megapathdsl.net> on 2001/02/15 03:53:27 UTC

NullPointerException trying to parse a simple XML file.

This should be a pretty simple question.  Running the following code:


    try {
      XMLReader parser =
XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
      parser.setContentHandler(contentHandler);
      parser.setErrorHandler(errorHandler);
      parser.setEntityResolver(new FeedEntityResolver(dtdPath));
      parser.setFeature("http://xml.org/sax/features/validation", true);
      try {
        parser.parse(uri);
      }
      catch (IOException e) {
        throw new FeedException("IOException, error reading URI: " +
e.getMessage(), e);
      }
      catch (SAXException e) {
        e.printStackTrace();
        throw new FeedException("Error in parsing: " + e.getMessage(), e);
      }
    }
    catch (SAXException e) {
      throw new FeedException("Unable to create parser.", e);
    }

where
contentHandler is a valid ContentHandler
errorHandler is a valid ErrorHandler
FeedEntityResolver is a valid Entity Resolver
uri is a valid absolute filename.

I am having the following Exception thrown:

java.lang.NullPointerException
 at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:878)
 at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:900)

No methods on my ErrorHandler, ContentHandler, or EntityResolver are ever
getting called.  Does anyone have any idea what I am missing?  The problem
seems to be contained within the parser code....

Any help is greatly appreciated.

Brad

RE: Windows Paths

Posted by Brad O'Hearne <ca...@megapathdsl.net>.
I must still be missing something. Neither

parser.parse("c:/test/data.xml");

or

parser.parse("file://c:/test/data.xml");

are working.  They are both causing a NullPointerException to be thrown,
same as the "c:\test\data.xml" string below.

Any other ideas, or have I missed something?

Brad

-----Original Message-----
From: Milind Gadre [mailto:milind@ecplatforms.com]
Sent: Monday, February 19, 2001 12:56 PM
To: xerces-j-user@xml.apache.org
Subject: Re: Windows Paths


Brad, use forward slashes ... c:/a/b/c

Regards...

Milind Gadre
ecPlatforms, Inc
901 Mariner's Island Blvd, Suite 565
San Mateo, CA 94404
C: 510-919-0596
F: 815-352-0779
milind@ecplatforms.com

>
> parser.parse("c:\test\data.xml");
>



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Windows Paths

Posted by Milind Gadre <mi...@ecplatforms.com>.
Brad, use forward slashes ... c:/a/b/c

Regards...

Milind Gadre
ecPlatforms, Inc
901 Mariner's Island Blvd, Suite 565
San Mateo, CA 94404
C: 510-919-0596
F: 815-352-0779
milind@ecplatforms.com

> 
> parser.parse("c:\test\data.xml");
> 



Windows Paths

Posted by Brad O'Hearne <ca...@megapathdsl.net>.
Hello all...

I am trying to figure out what the proper format is to specify an absolute
path on a Windows platform as the URI for the parse method.  If I have an
XMLReader called parser, the following:

parser.parse("c:\test\data.xml");

will not work.  I am finding this same issue a bit of an problem when trying
to resolve the dtd in the EntityResolver as well, since the resolveEntity
method is receiving a systemId that includes path info, as in
file:///test/dtd/data.dtd.  Specifically, on a Windows platform, how do you
include the drive letter in the URI?

Thanks in advance.

Brad


Re: NullPointerException trying to parse a simple XML file.

Posted by Elena Litani <hl...@jtcsv.com>.
Hi, Brad,
It is hard to say what is going on without any additional info. I
suspect you have some error in your code, cause I don't recall anybody
reporting this kind of behaviour before.
If you still need help, please, attach your .java files + sample file.

Thank you,
Elena

> Brad O'Hearne wrote:
> 
> This should be a pretty simple question.  Running the following code:
> 
> 
>     try {
>       XMLReader parser =
> XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
>       parser.setContentHandler(contentHandler);
>       parser.setErrorHandler(errorHandler);
>       parser.setEntityResolver(new FeedEntityResolver(dtdPath));
>       parser.setFeature("http://xml.org/sax/features/validation",
> true);
>       try {
>         parser.parse(uri);
>       }
>       catch (IOException e) {
>         throw new FeedException("IOException, error reading URI: " +
> e.getMessage(), e);
>       }
>       catch (SAXException e) {
>         e.printStackTrace();
>         throw new FeedException("Error in parsing: " + e.getMessage(),
> e);
>       }
>     }
>     catch (SAXException e) {
>       throw new FeedException("Unable to create parser.", e);
>     }
> where
> contentHandler is a valid ContentHandler
> errorHandler is a valid ErrorHandler
> FeedEntityResolver is a valid Entity Resolver
> uri is a valid absolute filename.
> 
> I am having the following Exception thrown:
> 
> java.lang.NullPointerException
>  at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:878)
>  at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:900)
> 
> No methods on my ErrorHandler, ContentHandler, or EntityResolver are
> ever getting called.  Does anyone have any idea what I am missing?
> The problem seems to be contained within the parser code....
> 
> Any help is greatly appreciated.
> 
> Brad

RE: NullPointerException trying to parse a simple XML file.

Posted by Brad O'Hearne <ca...@megapathdsl.net>.
One correction....the fatalError method on my ErrorHandler is getting
called....but there isn't much detail, just what is below...any ideas?

Brad
  -----Original Message-----
  From: Brad O'Hearne [mailto:cabodog@megapathdsl.net]
  Sent: Wednesday, February 14, 2001 6:53 PM
  To: xerces-j-user@xml.apache.org
  Subject: NullPointerException trying to parse a simple XML file.


  This should be a pretty simple question.  Running the following code:


      try {
        XMLReader parser =
XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
        parser.setContentHandler(contentHandler);
        parser.setErrorHandler(errorHandler);
        parser.setEntityResolver(new FeedEntityResolver(dtdPath));
        parser.setFeature("http://xml.org/sax/features/validation", true);
        try {
          parser.parse(uri);
        }
        catch (IOException e) {
          throw new FeedException("IOException, error reading URI: " +
e.getMessage(), e);
        }
        catch (SAXException e) {
          e.printStackTrace();
          throw new FeedException("Error in parsing: " + e.getMessage(), e);
        }
      }
      catch (SAXException e) {
        throw new FeedException("Unable to create parser.", e);
      }

  where
  contentHandler is a valid ContentHandler
  errorHandler is a valid ErrorHandler
  FeedEntityResolver is a valid Entity Resolver
  uri is a valid absolute filename.

  I am having the following Exception thrown:

  java.lang.NullPointerException
   at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:878)
   at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:900)

  No methods on my ErrorHandler, ContentHandler, or EntityResolver are ever
getting called.  Does anyone have any idea what I am missing?  The problem
seems to be contained within the parser code....

  Any help is greatly appreciated.

  Brad