Thanks Tomm, my problem has been resolved but thanks for reminding me about
the case sensitive comparison; I fixed it. For the history, here's my parser
and my xml file: (<data> is my root element and within this element there is
a sequence of <entry><date><value><change> elements.)
******************************************************************
import java.util.*;
import java.io.*;
import java.net.*;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
/**
* Parser.java
*
* @author Panagiotis Plevrakis
* @version 1.0, 05/18/02
*/
public class Parser extends DefaultHandler {
protected Vector vector = new Vector();
private String entry, date, value, change, tempstring;
private Data data = null;
public Vector readData() {
return vector;
}
public void parse(String file) {
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setValidating(true);
SAXParser saxParser = spf.newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();
xmlReader.setContentHandler(this);
xmlReader.setErrorHandler(this);
String urlstring = "file:" +
new File (file).getAbsolutePath();
URL url = new URL(urlstring);
URLConnection connection = url.openConnection();
InputStream inputstream = connection.getInputStream();
InputSource inputsource = new InputSource(inputstream);
xmlReader.parse(inputsource);
} catch (Throwable err) {
System.out.println(err.getMessage());
}
}
public void startElement(String namespaceURI, String localName,
String qName, Attributes atts) throws SAXException {
tempstring = "";
}
public void endElement(String uri, String localName,
String qName) throws SAXException {
if (qName.equals("entry")) {
entry = tempstring;
} else if (qName.equals("date") ) {
date = tempstring;
} else if (qName.equals("value")) {
value = tempstring;
} else if (qName.equals("change")) {
change = tempstring;
vector.add(new Data(entry, date, value, change));
}
}
public void characters(char[] ch, int start, int length) throws
SAXException {
String charactersfound = new String(ch, start, length).trim();
tempstring = tempstring + charactersfound;
}
}
*******************************************************************
<?xml version="1.0"?>
<data xmlns="" xmlns:xsi="xaa.xsd">
<entry>1</entry>
<date>May 20, 2002</date>
<value>2402.07</value>
<change>0.53</change>
<entry>2</entry>
<date>May 21, 2002</date>
<value>2498.07</value>
<change>1.43</change>
</data>
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.
To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm