• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Compiling application to parse xml file!

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All
I'm using ibm parser,first of all do i need to set classpath to anything?i believe so.
my classparh setting is :C:\IBMCON~1c:\jakarta-tomcat\lib\servlet.jar;c:\jakarta-tomcat\lib\jasper.jar;c:\jakarta-tomcat\src\javax\servlet;c:\xml4j\xml4j.jar;c:\xml4j\xml4j-3_1_1\samples\sax;c:\xml4j\xml4 j-3_1_1\src;
I'm trying to compile the following application and i get this message:java.lang.classnotfoundexception
the file is:
package com.psol.xbe;
import org.xml.sax.*;
import org.xml.sax.helpers.ParserFactory;
public class Cheapest extends HandlerBase
{
protected double min=Double.MAX_VALUE;
protected String vendor = null;
public void startElement(String name,AttributeList attributes)
{
if(name.equals("price"))
{
String attribute = attributes.getValue("price");
if(null!=attribute)
{
double price = toDouble(attribute);
if(min>price)
{
min=price;
vendor=attributes .getValue("vendor");
}
}
}
}
protected double toDouble(String string)
{
Double stringDouble = Double.valueOf(string);
if(null != stringDouble)
return stringDouble.doubleValue();
else
return 0.0;
}
public String getVendor()
{
return vendor;
}
public double getMinimum()
{
return min;
}
protected static final String PARSER_NAME = "com.ibm.parsers.SAXParser";
public static void main(String args[]) throws Exception
{
/*
if(args.length <1)
{
System.out.println("java com.psol.xbe.CheapestClfilename ");
return ;
}
*/
Cheapest cheapest = new Cheapest();
Parser parser = ParserFactory.makeParser(PARSER_NAME);
parser.setDocumentHandler(cheapest);
parser.parse("c:/javaMatt/prices.xml");
System.out.println("the cheapest offer is " + cheapest.getVendor() + " $" + cheapest.getMinimum() + ')');
}
}
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic