Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help "Error parsing XML document: null"

 
Eric lau
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some code like this:
XMLReader parser = null;
String parserClass = System.getProperty("org.xml.sax.driver",
"org.apache.xerces.parsers.SAXParser");
try {
parser = XMLReaderFactory.createXMLReader(parserClass);
// Set entity resolver, if needed
if (entityResolver != null) {
parser.setEntityResolver(entityResolver);
}
// Set error handler, if needed
if (errorHandler != null) {
parser.setErrorHandler(errorHandler);
}
// Register content handler
parser.setContentHandler(trade_Code);
} catch (SAXException e) {
throw new IOException("Could not load XML parser: " +
e.getMessage());
}
InputSource inputSource = new InputSource(reader);
try {
parser.setFeature("http://xml.org/sax/features/validation", new Boolean(validate).booleanValue());
parser.parse(inputSource);
} catch (SAXException e) {
throw new IOException("Error parsing XML document: " +
e.getMessage());
}
sometime it is work,sometime it throw Exception
"Error parsing XML document: null", anyone know what it is wrong?
help!
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can u give us some insight into the trace?
where is it throwing the null error.
When u say it works , you mean it behaves differently @ different times for the same input xml file?
 
Eric lau
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
When it works , the parser has the same input xml file!
The message is threw at:
try {
parser.setFeature("http://xml.org/sax/features/validation", new Boolean(validate).booleanValue());
parser.parse(inputSource);
} catch (SAXException e) {
throw new IOException("Error parsing XML document: " +
e.getMessage());
}
So ,null is return by e.getMessage().
Do you know what is wrong?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic