You are using SAX? Then my guess is you are making the standard error, where you assume that the characters() method always returns you the entire text node all at once. That isn't the case. The parser can break a text node into pieces and call characters() once for each piece. And parsers do that.
Joined: Mar 20, 2007
Hi there, I have to do exactly the same task that you are doing but I am unable to do it as i dont have much experience with parsing. I understand the basics of using SAX parser and how startElement, endElement, and characters are called.
My problem is how do we extract this data and keep it in some meaningful form. Like for example how do i keep track of which menu has which sub menus and then what menuitems are under each submenu. Plus i need to keep track of attributes as well as they will effect runtime menus in GUI. Do I need to use some kind of data structure for this.
Your help with be highly appreciated. Regards, nomi
Thanks Paul for pointing that behavior. Now i used a StringBuffer inside characters() method to and append its values and then making its length to 0 at startElement() method and endElement() method. Now it got solved.
Code which i used is
Regarding Nomi Malik, I will explain you how i handled the situation in my code.I will have separate variable for menuName,menuItemName,subMenuName and subMenuItemName which takes the corresponding values from XML and i used a HashMap to hold all the created menus and menuitems.And while parsing once i see a closing tag in XML i will just create the appropriate component and put it to Frame.After parsing the complete XML file i will have a Frame which holds all the components packed and i will finally call frame.setVisible(true);
This one is my implementation explained in short. If you feel this one is not effective your are welcome to provide feedback.