File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Problem in reading xml file?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Problem in reading xml file??" Watch "Problem in reading xml file??" New topic

Problem in reading xml file??

Gaurav Jain
Ranch Hand

Joined: Mar 11, 2004
Posts: 108
i am trying to read a xml file and convert in to a DOM object.
Following is the code:
DocumentBuilder objBuilder = objFactory.newDocumentBuilder();
File f = new File("P:/My Documents/IBM/wsappdev51/workspace/MyXML/xmlproperties/NewFile.xml");
objDOM = objBuilder.parse(f);

I am getting the DOM object as null.
I guess its not able to find the xml file although when i print "f" it gives me the correct path of the file.
What is the problem??
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
I've never heard of the DocumentBuilder#parse(...) method returning a null (I believe the JAXP specification states that a compliant parser implementation should always either return an org.w3c.dom.Document object or throw an exception). Which parser implementation are you using?

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
I agree. Here's the link:
subject: Problem in reading xml file??
jQuery in Action, 3rd edition