This week's book giveaway is in the Open Source forum.
We're giving away four copies of Programmers Guide to Apache Thrift and have Randy Abernethy on-line!
See this thread for details.
Win a copy of Programmers Guide to Apache Thrift this week in the Open Source forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Problem in reading an external DTD file  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am trying to parse an XML file using jaxp. The parser is set to operate in the validating mode. The program compiles well but every time I run it, gives me the following error:
-----------------------------------------------------------------
FATAL: line 2: External entity not found: "file://AutoLiability.dtd".
Exception in thread "main" org.xml.sax.SAXParseException: External entity not found: "fil
e://AutoLiability.dtd".

-----------------------------------------------------------------
The XML file and the corresponding dtd are in the same folder and the DOCTYPE is specified as follows:
<!DOCTYPE AutoLiability SYSTEM "AutoLiability.dtd">
-----------------------------------------------------------------
The snapshot of code is al so given below:
javax.xml.parsers.SAXParser sp = spf.newSAXParser();
// Create a SAX input source for the file argument
org.xml.sax.InputSource input=new InputSource(new FileReader(File1));
// Give the InputSource an absolute URL for the file, so that
// it can resolve relative URLs in a <!DOCTYPE> declaration
input.setSystemId("file://" + File1.getAbsolutePath());
// Create an instance of this class; it defines all the handler methods
ListServlets1 handler = new ListServlets1();
// Finally, tell the parser to parse the input and notify the handler
sp.parse(input, handler);
TIA !
Milind
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On a totally unrelated note,
Your name does not comply with the JavaRanch naming policy. Please choose one that meets the requirements.
Thanks!
Ajith
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where exactly does your DTD reside?? Is it directly under the root directory ?? The parser is looking under the root...
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Milind K:
Hi All,
I am trying to parse an XML file using jaxp. The parser is set to operate in the validating mode. The program compiles well but every time I run it, gives me the following error:


Try these two things
(1) Change "file://" to "file:///"
(2) Put the dtd file in the same directory as the XML file
I hope this can help.
 
Listen. That's my theme music. That's how I know I'm a super hero. That, and this tiny ad told me:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!