Straight from the Heart

XML Entity Resolver

Posted on: July 15, 2008


Today, while creating a xml entity resolver, i have got struck in a trifling situation. I was using the throws keyword for handling exception instead of try catch block at InputStream instance creation method for a particular url path-getInputStreamFromDB(String urlString), and due to that, in case of error, control was going to the ValidatingErrorHandler class (a error handler used by the parser), which was again pushing it to the ExternalEntityresolver class (an Entity Resolver) and this whole thing was going into a recursion.


code snippets to give an idea-

ExternalEntityResolver externalEntitityResolver = new ExternalEntityResolver();

            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();






            ValidatingErrorHandler validator = new ValidatingErrorHandler();


            DocumentBuilder documentBuilder = factory.newDocumentBuilder();






privateInputStream getInputStreamFromDB(String urlString) throwsMalformedURLException, IOException {

            InputStream inputStream = null;

            String xmlPath=   “D:\\eclipse workspace\\PIF_VALIDATION\\resource\\AddressBook-ZipToCityEPD.xsd”;

            //xmlPath=new File(xmlPath).toURI().toString();

            URL url = newURL(xmlPath);          Origin of exception

            URLConnection con = url.openConnection();


            if(con != null){

                  inputStream = con.getInputStream();





Later, when I have used try-catch block to check the stacktrace, encountered the real culprit- a fresh exception. This exception originates at the time of URL instance creation for a given path String.



path= “D:\\eclipseworkspace

String \\PIF_VALIDATION\\resource\\AddressBook-ZipToCityEPD.xsd”;

URL url = new URL(path);           

            URLConnection con = url.openConnection();


            if(con != null){

                  inputStream = con.getInputStream();


            }catch (MalformedURLException e) {

                  e.printStackTrace();// TODO: handle exception unknown protocol: d

      at<init>(Unknown Source)

      at<init>(Unknown Source)

      at<init>(Unknown Source)

      at com.XXX.xml.ExternalEntityResolver.getInputStreamFromDB(


It seems as if String path is not interpreted as a file reference and because of this, it is throwing MalformedURLException with this “unkown protocol d” message. Preferably I feel it should be handled by URL class code by checking the format of the path String. For solving this problem, we need to create a valid URL in code itself.



Just put this line of code before the creation of URL instance-


path=new File(path).toURI().toString();

URL url = new URL(path);


There is one more way, more simpler one to achieve the purpose

Simply append “file:///” at the beginning of path String and it would solve the purpose.


Path=”file:/// “+path;

URL url = new URL(path);


Tags: ,

2 Responses to "XML Entity Resolver"

Thanks for this tip, I was really blocked; and the error message was not so clear.

Hi Zef,

Thanks for your kind comment.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s



The Calendar..तारीख

July 2008
« Jun   Sep »

गुफ्तुगू ….

Sindhu on How to integrate Sonar with…
Naga Anji on EMMA: a free Java code coverag…
Manu on Hiring
jarvarm on Hiring
Manu on Hiring



  • 38,854 hits


The Falls Of Falloch / Eas Fallach

Red--necked Phalarope

Macro Monday 2017-06-25 (5D_32A9977-89)

Broken for Macro Mondays 26th June 2017

Broken Pencils

Smashed - HMM


He Loves Me -He Loves Me Not

There are few things that stay so perfectly useful when broken

Magic Bulb

More Photos

Thanks for the Visit…आने का शुक्रिया

website statistics

Rumbling of Mind

  • Sushil Kumar has won his second Olympic medal, become the first Indian to win two individual Olympic medals for India. Respect. 4 years ago
  • Satyamev Jayate-A great initiative by Aamir Khan & company....must watch on star plus/DD National every Sunday 11:00 AM 5 years ago
  • @sujeetkant number is changed..sent on your linkedin.. 5 years ago
  • @sujeetkant dude I m fine..howz life at you end ..long time 5 years ago
  • In real bad mood.. :( Banged my car today.. 5 years ago


Top Clicks..पसंदीदा

  • None

The Selected One’s..चुनिन्दा

U come from..

%d bloggers like this: