Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Problem with Xerces/XOMHandler.inInternalSubset reading from File but not FileReader or FileInputStream

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Peter Murray-Rust <pm286 AT cam.ac.uk>
  • To: XOM API for Processing XML with Java <xom-interest AT lists.ibiblio.org>
  • Subject: [XOM-interest] Problem with Xerces/XOMHandler.inInternalSubset reading from File but not FileReader or FileInputStream
  • Date: Mon, 14 Sep 2009 19:37:53 +0100

We have the following code which produces runtime errors on some machines
but not others. We are using xom-1.2.3 and Java 1.6.0_13-b03

File b511922g.xml contains:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE article SYSTEM "http://www.rsc.org/dtds/rscart37.dtd";>
<article/>

XomTester.java contains:
package d.tmp;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import nu.xom.Builder;
import nu.xom.Document;
import nu.xom.ParsingException;
import nu.xom.ValidityException;

public class XomTester {

public static void main(String[] args) throws ValidityException,
FileNotFoundException, ParsingException, IOException {
Document doc = new Builder().build(new FileReader("b511922g.xml"));
System.out.println("worked with filereader");

FileInputStream fis= new FileInputStream(new File("b511922g.xml"));
doc = new Builder().build(fis);
System.out.println("worked with FileInputStream");

File f = new File("b511922g.xml");
System.out.println(f.getAbsolutePath());
doc = new Builder().build(new File("b511922g.xml"));
System.out.println("worked with file");
}
}

The parse works on the first two but fails on the third on some machines
with:


C:\My Documents\workspace\TestXOM\src>java -classpath %classpath%
d.tmp.XomTester


worked with filereader
worked with FileInputStream
C:\My Documents\workspace\TestXOM\src\b511922g.xml
Exception in thread "main" nu.xom.ParsingException in
file:///C:/My%20Documents/
workspace/TestXOM/src/b511922g.xml
at nu.xom.Builder.build(Unknown Source)
at nu.xom.Builder.build(Unknown Source)
at nu.xom.Builder.build(Unknown Source)
at d.tmp.XomTester.main(XomTester.java:26)
Caused by: java.lang.NullPointerException
at nu.xom.XOMHandler.inInternalSubset(Unknown Source)
at nu.xom.XOMHandler.attributeDecl(Unknown Source)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.attribut
eDecl(Unknown Source)
at
com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDProcessor.attribute
Decl(Unknown Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.scanAttlist
Decl(Unknown Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.scanDecls(U
nknown Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.scanDTDExte
rnalSubset(Unknown Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDri
ver.dispatch(Unknown Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDri
ver.next(Unknown Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$Prolog
Driver.next(Unknown Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(U
nknown Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
l.scanDocument(Unknown Source)
at
com.sun.org.apache.xerces.internal.parsers.DTDConfiguration.parse(Unk
nown Source)
at
com.sun.org.apache.xerces.internal.parsers.DTDConfiguration.parse(Unk
nown Source)
at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown So
urce)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Un
known Source)
... 4 more


I am surprised that changing from a FileReader to a File generated the
error, and also that it appears to come from the Internal Subset. It is not
easy to generate this error message on demand since it is not thrown on my
machine. I suspect it is a Xerces problem that may be very difficult to
track down. We assume we are working with the Xerces packaged in the JRE
since we have stripped all jars from the classpath.

Any help (at least an explanation) would be helpful.

P.


--
Peter Murray-Rust
Reader in Molecular Informatics
Unilever Centre, Dep. Of Chemistry
University of Cambridge
CB2 1EW, UK
+44-1223-763069




Archive powered by MHonArc 2.6.24.

Top of Page