• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SAX Parsing Problem

 
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My application will parse the XML file given as argument and produces GUI based on the XML tags.In that one i had problem in parsing '&' character.

I got this exception,


After reading W3C documentation here.

I changed '&' in the XML file to & amp;(no whitespace) then i am able to run my application but the GUI which gets generated has one problem

In my XML for creating a menu i will use the following tag

then i can able to get the menu properly but if i change the XML as

then i am able to get the menu with label only others.
Why is this happening?
[ April 09, 2008: Message edited by: Balasubramanian Chandrasekaran ]
 
Marshal
Posts: 28258
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic