Hello, I am faced with a problem trying to use SAX - my class is as shown.
The problem is that the data structure "cm" is getting populated correctly
when printed from the endDocument() callback method, but getModel() call
subsequently does not return the results of the parsed XML.
As I am relatively new to SAX, I am wondering why this is - it doesn't do me
any good to see my data structure lost, after I have successfully populated
it from XML!
Thanks, and please email me directly on the reply.
Thanks, Paul
pa********@NOSPAMcomcast.net
public class ContactsModelBuilder extends DefaultHandler {
protected ContactsModel cm;
...
public void buildModel (String filename) {
...
try {
SAXParser saxParser = factory.newSAXParser();
saxParser.parse(new File(filename), handler);
} catch (SAXParseException spe) {
...
}
public void endDocument()
throws SAXException
{
if (cm != null) {
// THIS CALL IS GOOD!
// THIS CALL IS GOOD!
// THIS CALL IS GOOD!
cm.print();
}
}
public ContactsModel getModel () {
// THIS CALL RETURNS NULL *AFTER* endDocument()
// THIS CALL RETURNS NULL *AFTER* endDocument()
// THIS CALL RETURNS NULL *AFTER* endDocument()
return cm;
}