xml file parsing using DocumentFactory

Hai ,

I dont know how to read an xml document using DocumentFactory ..

i am using netbeans and jdk1.6. do i have to download any jar files and put those in lib. Can any one tell me what i have to fallow.

my sample code is:

import org.w3c.dom.Document;

import org.w3c.dom.NodeList;

import org.w3c.dom.Node;

import org.w3c.dom.Element;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import java.lang.*;

public class Info extends Object {

public static void main (String args[])

{

String myFile = "C://myinfo.xml";

//Initialize the DOM Object

Document myDoc = null;

try {

DocumentBuilderFactory docbuilderfactory = DocumentBuilderFactory.newInstance();

DocumentBuilder docbuilder = docbuilderfactory.newDocumentBuilder();

myDoc = docbuilder.parse(myFile);

System.out.println(myDoc);

} catch (Exception e) {

e.printStackTrace();

System.err.println("Cannot read the file: "+e.getMessage());

}

}

}

i can compile but at the run time i am not able read the "C://myinfo.xml"

Any one having idea on this kindly guide me

[1236 byte] By [kurra99a] at [2007-11-27 3:13:01]
# 1
No one to help me
kurra99a at 2007-7-12 8:15:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Your code works fine provided "C://myinfo.xml" exists and is a well-formed XML file.
prgguya at 2007-7-12 8:15:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
yes it is well formed i validated and checked. i think the problem is with jar files placing.. can you tell what jar files i have to download and where to place them.Thankskurra
kurra99a at 2007-7-12 8:15:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
> i think the problem is with jar files placing.I doubt that. But I notice you haven't said anything about how you know you have a problem. What happens when you run the code? If you get an exception, post the stack trace here.
DrClapa at 2007-7-12 8:15:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5
Hi,I am not getting any stacktrace error.. when the time it comes to read the document,. it just skip that part.i just put system.out.println(infodoc);it prints [#document:null]
kurra99a at 2007-7-12 8:15:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6
Hi,I am not getting any stacktrace error.. when the time it comes to read the document,. it just skip that part.i just put system.out.println(myDoc);it prints [#document:null]
kurra99a at 2007-7-12 8:15:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7
i am not able to understand i parts i have to check. compling fine, only the reading xml document from the c drive.i have gone through some reference but i didnt get it. like to place Jdom1.0 in the java/lib.can you driect me in right way...plzThankskurra
kurra99a at 2007-7-12 8:15:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 8
> i just put system.out.println(myDoc);> > it prints [#document:null]Yes, that's normal. That doesn't mean the parse failed, it just means you printed the nodeValue of the root element, which is null. (Read the API documentation for the Node interface.)
DrClapa at 2007-7-12 8:15:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 9
Its right, i checked every thing from the stratch. i first put the jdom-1. in java/jdk1.6.0_01/lib/ and then i checked the xml file from the root node to it ending..finaly i got the result...Thank You very much.Kurra.
kurra99a at 2007-7-12 8:15:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...