You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by loic tregan <lt...@hotmail.com> on 2000/10/24 17:18:29 UTC

bug xerces1.2.1 : unable to laod from File

Hi all,

It used to work with previous version, but now DocumentBuilder.parse(File) 
does not work any more :

  static void TestParse_reported() throws Exception{
    String fileName = "c:/temp/conge.xml";
    File f = new File( fileName);
    InputSource input = new InputSource( "file:"+fileName );
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance ();
	  DocumentBuilder db = dbf.newDocumentBuilder ();
   try{
  	  db.parse( input );
      System.out.println("Load from InputSource OK");
    } catch(Exception x) {
      System.out.println("Unable to load from InputSource");
    }
   try{
  	  db.parse( f );
      System.out.println("Load from File OK");
    } catch(Exception x) {
      System.out.println("Unable to load from File");
    }
  }


I suggest that javax.xml.parsers.DocumentBuilder should be modified like 
this:

    public Document parse(File file)
    throws SAXException, IOException, IllegalArgumentException {
        if (file==null) throw new IllegalArgumentException();
        // Thanks to Kevin Kress <Ke...@oracle.com> for pointing
        // out this bug.
        return(this.parse(new 
InputSource(>>"file:"<<+file.getAbsolutePath())));
    }

A better patch would be to understand why InputSource("c:/temp/x.html") is 
not valid ( the correct syntax is InputSource("file:c:/temp/x.html") ); the 
solution seems to be somewhere around in 
org.apache.xerces.readers.DefaultEntityHandler line 433.

loic

PS: I've not subscribe to the mailing list, please put me in CC.
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at 
http://profiles.msn.com.