This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Problem Parsing XML file with JDOM. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Problem Parsing XML file with JDOM." Watch "Problem Parsing XML file with JDOM." New topic
Author

Problem Parsing XML file with JDOM.

Pallavi Mahajan
Greenhorn

Joined: Apr 21, 2003
Posts: 12
Hello All,
I've just started working on JDOM and trying to parse XML file with JDOM.
I've set classpath to jdom.jar, xerces.jar and JDOM_HOME is properly set.
CLASSPATH: .;C:\Program Files\Common Files\Mercury Interactive\SharedFiles\JavaAddin\classes;C:\Program Files\Common Files\Mercury Interactive\SharedFiles\JavaAddin\classes\mic.jar;C:\CMVC95\CMVC\EXE\cmvc.jar;c:\jdk1.3.1_07\bin\.;c:\jdk1.3.1_07\lib\.;C:\jdom-b9\jdom-b9\build\.;C:\jdom-b9\jdom-b9\lib\xerces.jar;C:\jdk1.3.1_07\jre\lib\ext\.;
JDOM_HOME: C:\jdom-b9\jdom-b9\build\.;
JAVA_HOME: c:\jdk1.3.1_07;

C:\General>javac EchoXML.java
EchoXML.java:17: cannot access org.w3c.dom.Element
file org\w3c\dom\Element.class not found
Document d2 = dombuild.build(new java.io.File(args[0]));
^
1 error
I'm getting above error.
EchoXML.java looks like:
import java.io.*;
import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.input.DOMBuilder;
import org.jdom.output.XMLOutputter;

public class EchoXML {
public static void main(String[] args) {

try {
//SAXBuilder saxbuild = new SAXBuilder();
DOMBuilder dombuild = new DOMBuilder();
//Document d = saxbuild.build(new File(args[0]));
Document d2 = dombuild.build(new java.io.File(args[0]));

XMLOutputter xmlout = new XMLOutputter("%%%%%");
xmlout.output(d2, System.out);
System.out.println("\n----------------------------");
//xmlout.setTrimText(true);
//xmlout.setIndent(false);
//xmlout.output(d2, System.out);
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
Can anybody please help me in this error. I'm trying since few days and still I am there where I had started:-(
Thank You,
Pallavi
Pavel Halas
Ranch Hand

Joined: Jul 05, 2003
Posts: 35
It's hard to find your problem. But try this.
Naren
Greenhorn

Joined: Jul 21, 2003
Posts: 23
The error message can't get any clearer than this:
"cannot access org.w3c.dom.Element"
You need to add the following line at the top your code (below any package statements)
import org.w3c.dom.*;


<a href="http://www.mqtips.com" target="_blank" rel="nofollow">MQMessenger</a> - free Java app for MQSeries
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem Parsing XML file with JDOM.
 
Similar Threads
JDOM problem -- where to ask?
how to set classpath for JDOM
JDOM works normally not with JSP
Change XML element using Java
NoClassDefFoundError with JDOM