Im having an issue opening the
stackoverflow posts XML dump using the java sax parser. It recognizes the end of each
element but seems to skip the startElement method. Im using the example
code:
try
{
SAXParserFactory factory =
SAXParserFactory.newInstance();
SAXParser saxParser =
factory.newSAXParser();
DefaultHandler handler = new
DefaultHandler() {
public void startElement(String uri, String
localName, String qName,
Attributes attributes) throws SAXException
{
System.out.println("Start Element :" +
qName);
}
public void endElement(String uri,
String localName,
String qName) throws SAXException {
System.out.println("End Element :" + qName);
}
public void characters(char ch[], int start, int length) throws
SAXException {
}
};
saxParser.parse(filename,
handler);
The
XML is structured simply as a row with a number of
attributes:
"postTypeID=1"
AcceptedAnswer...>
and
the output from the code above is
simply:
End Element
:row
I have
tried adding @Override annotations to the methods inside the defaultHandler however it
throws an error if i try to override the startElement. Can anyone recommend how to
correct this issue and why startElement cannot be overriden?
No comments:
Post a Comment