#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Posts
    11
    Rep Power
    0

    Exclamation XML and JSP (Need urgent help please)


    Hey All

    Ok i'm trying to understand the Article Sun Published on thier website:
    Web Application Development with JSP and XML
    http://developer.java.sun.com/develo...ml/WebAppDev2/

    With the SAX parsing section they create 2 .java files:
    MySAXParserBean.java and MyElement.
    They state that MySAXParserBean is using the MyElement class.

    I can compile MyElement.java perfectly but as soon as I try and compile MySAXParserBean.java i get the following error...


    # javac MySAXParserBean.java
    MySAXParserBean.java:14: cannot resolve symbol
    symbol : class MyElement
    location: class saxbean.MySAXParserBean
    private MyElement current = null;
    ^
    MySAXParserBean.java:36: cannot resolve symbol
    symbol : class MyElement
    location: class saxbean.MySAXParserBean
    current = new MyElement(
    ^
    2 errors


    Can anyone please tell me why this is happening...

    Here is the MySAXParserBean.java

    package saxbean;

    import java.io.*;
    import java.util.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.DefaultHandler;
    import javax.xml.parsers.SAXParserFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.SAXParser;

    public class MySAXParserBean extends DefaultHandler implements java.io.Serializable {
    private String text;
    private Vector vector = new Vector();
    private MyElement current = null;

    public MySAXParserBean() {
    }

    public Vector parse(String filename) throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setValidating(false);
    SAXParser saxParser = spf.newSAXParser();
    // create an XML reader
    XMLReader reader = saxParser.getXMLReader();
    FileReader file = new FileReader(filename);
    // set handler
    reader.setContentHandler(this);
    // call parse on an input source
    reader.parse(new InputSource(file));
    return vector;
    }

    // receive notification of the beginning of an element
    public void startElement (String uri, String name,
    String qName, Attributes atts) {
    current = new MyElement(
    uri, name, qName, atts);
    vector.addElement(current);
    text = new String();

    }

    // receive notification of the end of an element
    public void endElement (String uri, String name,
    String qName) {
    if(current != null && text != null) {
    current.setValue(text.trim());
    }
    current = null;
    }

    // receive notification of character data
    public void characters (char ch[], int start,
    int length) {
    if(current != null && text != null) {
    String value = new String(ch, start, length);
    text += value;
    }
    }
    }


    Thanking you in advance
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    Maine
    Posts
    9
    Rep Power
    0
    is MyElement in the saxbean package?

IMN logo majestic logo threadwatch logo seochat tools logo