This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SAX:Why content handler's characters() method is called and print multiple space string.

 
raj malhotra
Ranch Hand
Posts: 288
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI
I am overriding these methods in my ContentHandler as shown below.





and xml which SAX parser, parse is person.xml .I am passing this xml as first argument.-




I am getting the output as


Can somebody please tell me the reason where parser is finding these strings with multiple spaces?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13044
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Those are the contents of Text type Nodes corresponding to the document formating lines.

2. Your implementation of characters method does not recognize the fact that characters may be called multiple times inside the content of a single element if the document is longer than a single input buffer.

Bill
 
raj malhotra
Ranch Hand
Posts: 288
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks William for your reply.How would i handle it if i want to show only the element name and and its value in the output?
 
Paul Clapham
Sheriff
Pie
Posts: 20155
23
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
raj malhotra wrote:How would i handle it if i want to show only the element name and and its value in the output?

You would use some if-statements which checked to see if the node in question was an Element node. And by the way, in DOM elements don't have values. Perhaps you're thinking of elements which only have a single child node which is a Text node? If you want to get that, then just write code to get the child. But you should be aware that it's possible for an Element node to have more than one child node. This is called "mixed content" and it's a perfectly normal thing to do.
 
raj malhotra
Ranch Hand
Posts: 288
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks William and Paul for your replies.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic