wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes DOM Parsing - Please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "DOM Parsing - Please help" Watch "DOM Parsing - Please help" New topic
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: 41574
    
  54
Can you read the file using java.io.File?


Ping & DNS - my free Android networking tools app
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: 41574
    
  54
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: 41574
    
  54
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: 18541
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DOM Parsing - Please help