Author
DOM Parsing - Please help
Vijay Verma
Greenhorn
Joined: Oct 21, 2005
Posts: 5
Hi Guys, I am trying to run the following very simple program on my machine to parse a very simple XML file. It just returns Document object NULL. Same code is working fine on another machine. Note: there is no silly mistake. i have valid xml file at valid place. Please help. import org.apache.xerces.parsers.*; import org.w3c.dom.*; import org.xml.sax.*; import java.io.*; class XML { public static void main(String [] args) { try{ String caseFile = "c:\\case-config\\config.xml"; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(caseFile); System.out.println("\n\n----" + doc); }catch(Exception e) { e.printStackTrace(); } } }
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35246
posted Oct 21, 2005 04:04:00
0
Can you read the file using java.io.File ?
Android apps – ImageJ plugins – Java web charts
Vijay Verma
Greenhorn
Joined: Oct 21, 2005
Posts: 5
Yes I can read files using java.io
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35246
posted Oct 21, 2005 04:23:00
0
What I meant was: can you read this particular file with code in this particular Java class?
Vijay Verma
Greenhorn
Joined: Oct 21, 2005
Posts: 5
yes same xml file i can read with java program.. and i tried with many xml files but no use.. actually when i say factory.setValidating(true); it gives some errors like Grammer not found etc. [ October 21, 2005: Message edited by: Vijay Verma ]
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35246
posted Oct 21, 2005 05:59:00
0
Does it work with validation turned off?
Vijay Verma
Greenhorn
Joined: Oct 21, 2005
Posts: 5
no becuase Document object is null.
Makarand Parab
Ranch Hand
Joined: Dec 10, 2004
Posts: 121
Hey Vijay Try this out and let me know import org.apache.xerces.parsers.*; import org.w3c.dom.*; import org.xml.sax.*; import java.io.*; class XML { public static void main(String[] args) { try{ String caseFile = "c:\\case-config\\config.xml"; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new File(caseFile)); System.out.println("\n\n----" + doc); }catch(Exception e) { e.printStackTrace(); } } }
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
The code you posted does not tell you that the "doc" variable contains null. It is possible that its toString() method returns null, or the 4-character string "null", as well. And considering that the getNodeValue() method of an Element node does return null (check the API documentation for org.w3c.dom.Node ), it's possible you have misidentified the problem.
subject: DOM Parsing - Please help