Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with Java+XML

 
Vids
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Vids
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic