Click to See Complete Forum and Search --> : ContentHandler help


vassilisa
01-26-2005, 02:39 AM
i'm using a SAXParser to parse a xml file, and a handler class to get and store the data into another java class.

i got the following classes in my program :
XmlUtil.java (to load xml) >
HelpHandler.java (handler class which implements ContentHandler)
HelpDetail (contains getter n setter method to store the data extracted)

my problem is, if i were to use the above design, is there anyway to return the populated java class (HelpDetail.java) back to the calling program(XmlUtil.java) from HelpHandler.java?

Khalid Ali
01-27-2005, 06:44 AM
do something like this.
in XmlUtil.java call the handler calss to take care of the xml

HelpHandler helpHandler = new HelpHandler(xmlFileInputStream);
//now in the HelpHandler make sure that all processing takes place from
//a call to the constructor, then create a getter method and use it like
//this, and declare an instance variable like this
HelpDetail helpDetail;
helpHandler.getXmlContents()//this should return an instance of HelpDetail ..
hope this gives you an idea

vassilisa
01-28-2005, 04:07 AM
thx for the idea.

this is wat i did:
i still have the XmlUtil class, and within this class i have a loadXml() and a global attribute called HelpDetail(which stores the info extracted from the XML). then i include the Handler class into XmlUtil.java as an inner class. this works fine.

but my concern is, if in the future i have more XML and handler class, XMlUtil will grow larger and larger. Coz my initial intention of creating XmlUtil is only purely as a util file to call the relevant Handler class and do the parsing.

cheers!