• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do i use an Entity Resolver Interface

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone kindly tell me how do i use an Entity Resolver interface. I tried using it, but i got an Exception -
org.xml.sax.SAXParseException: File "file:///C:/samples/book.dtd" not found.
My current working directory is C:/samples
and The DOCTYPE Statement in the xml file is
<!DOCTYPE main SYSTEM "book.dtd">
I want to place the book.xml and book.dtd files in some other directory.
the following is the code implemnting the resolveEntity method.
public InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) throws SAXException, IOException
{
if (systemId.equals("book.dtd"))
{
try
{
return new InputSource(file:///Some directory/book.xml");
}
catch(Exception e)
{
System.out.println("EXCEPTION = "+e);
return null;
}
}
else
{
return null;
}
}
Where have i gone wrong??
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The InputSource constructor that takes a String
is looking for the System Identifier. Try moving
that fully qualified URI
file:///Some directory/book.xml
up into the <DOCTYPE> in place of the
"book.dtd" in your example.
And the InputSource constructor call in your
example is missing a quote, but the compiler should
complain loud and clear about that.
Joe
 
author
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have checked that the file "c:\samples\book.dtd" really does exist?!
I'd suggest replacing "c:/" with "c|/" (i.e. replacing the colon with a vertical bar) or removing it altogether.
i.e.
"file:///C|/samples/book.dtd" or "file:///samples/book.dtd"
David
[This message has been edited by David Peterson (edited December 05, 2001).]
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Your name liinaa does not comply with the JavaRanch naming policy. We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please spare a moment and re-register with a name that meets the requirements.
Thanks!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I remember having the ruffly the same problem. I ended putting the dtd in a jarfile and retrieving it with Class.getResourceAsStream(String) instead. This way you do not have to worry about where the dtd is placed in relation to the xml file.
 
Life just hasn't been the same since the volcano erupted and now the air is full of tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic