This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Problem with Java+XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Problem with Java+XML" Watch "Problem with Java+XML" New topic
Author

Problem with Java+XML

Vids
Greenhorn

Joined: Oct 30, 2000
Posts: 8
I have jdk1.2.2. I am compiling a small java program with embedded XML document. The program is as follows:
import org.xml.sax.*;
public class BookCounter extends HandlerBase
{
private int count = 0;

public void countBooks() throws Exception
{
Parser p=new com.sun.xml.parser.ValidatingParser();
p.setDocumentHandler(this);
p.parse("file:///d:javaex/books.xml");
}
public static void main(String args[]) throws Exception
{
(new BookCounter()).countBooks();
}

public void startElement(String name,AttributeList atts) throws SAXException
{
if (name.equals("book"))
count++;
}
public void endDocument() throws SAXException
{
System.out.println("there are "+count+ "books");
}
}
During compilation it gives the error:
BookCounter.java:9: Class com.sun.xml.parser.ValidatingParser not found.
Parser p=new com.sun.xml.parser.ValidatingParser();
I am using kawa editor.
Please lemme know how to solve this. If there is any problem with class path please give the full steps to set up my classpath appropriately.
Thanks,
Vids.
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
You need to download JAXP1.1 from sun at http://developer.java.sun.com/developer/earlyAccess/xml/ and include the jaxp.jar and parser.jar in your classpath.
Hope this helps


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Vids
Greenhorn

Joined: Oct 30, 2000
Posts: 8
I have downloaded JAXP1.1 but where do I find parser.jar. It did not come along with the download:-(
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12759
    
    5
If that was really the code, you only import one package:
import org.xml.sax.*;
Naturally you get this error.
Class com.sun.xml.parser.ValidatingParser not found.

Bill
prabhu palanisamy
Greenhorn

Joined: Oct 30, 2000
Posts: 27
hi vids,
i think the problem is with setting the classpath.
in kawa goto classpath and set a new classpath to
xml.jar,give the correct path.i hope you use projectX sun parser.
if u use Xerces parser,then set the path to xerces.jar.
the problem is not with the code.
bye
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Java+XML
 
Similar Threads
javax xml parsers FactoryConfigurationError
xml/sax
java code and SAX
SAX parsing of xml file Tracing invalid characters
'reading' an xml document - what am i doing wrong?