Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

characters() callback for empty elements

 
Alagu Seenivasan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anybody know a SAX implementing parser which fires "character()" callback even for empty elements ?
Thank you,
Srini
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know of any, and it seems a very strange requirement. Remember that in XML, <a></a> is treated exactly the same as <a/>. Would you want an empty character string in both cases?
If I need to know whether any characters were supplied, I set a flag if any characters are supplied, and check it when I am notified of the end tag.
 
Alagu Seenivasan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This indeed is a strange requirement because I need to convert the xml into a fixed length text file where,if the element is not present there should be so many blanks. So after looking around I had already done exactly what you said.
In the "startelement" set a flag and remember the supposed length
and reset the flag in the "characters". check the flag in the "endelement" and do accordingly.
I know that the firing "characters" call back is (parser) implementation dependent.
My problem is solved for the time being. If I come across a better solution, I will post it here.
Thanks Frank.
[This message has been edited by Alagu Seenivasan (edited October 02, 2000).]
 
Sarada Bhasker
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alagu,
I would like to know how you solved the problem.
 
Alagu Seenivasan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assumption: characters() callback is not automatically fired for empty elements.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic