Well, unfortunately, RSS is supposed to be an XML dialect but in real life there is RSS-creation software that isn't as good as it should be. Or maybe people are using text editors to write RSS. Anyway, the end result is malformed XML.
You could just reject it (that would be The XML Way™). The alternative is to stop using an XML parser and use something else. I've heard about ROME for parsing RSS in Java but haven't ever used it myself.
Drew Lane
Ranch Hand
Joined: May 13, 2001
Posts: 296
posted
0
How would I reject it? It's not throwing an error.
Could I just reject the one element with the & or do you mean just leave out that whole feed (not a good solution).
Originally posted by Drew Lane: How would I reject it? It's not throwing an error.
It's not throwing an exception? Then you don't have malformed XML and therefore you don't have an unescaped ampersand.
My suspicion is that you're using a SAX parser and making the common error of assuming that the characters() method in your ContentHandler will always be passed the complete contents of a text node. That isn't the case. The parser is allowed to break text into pieces and call characters() once for each piece.
Drew Lane
Ranch Hand
Joined: May 13, 2001
Posts: 296
posted
0
Holy Cow!
You were right!
You rawk dude. :-)
Thanks,
-Drew
Marvin Serrano
Greenhorn
Joined: Mar 11, 2010
Posts: 5
posted
0
I'm having a similar problem with my XML parsing; it just stops whenever an ampersand is hit. How can I modify the characters() method to ignore that case? Any sample code would be greatly appreciated.
Of course you can't modify the parser to call the characters() method differently than what it does. You have to modify your code if you want to collect all of the character data inside an element together. See the first question in the XmlFaq.
This message was edited 1 time. Last update was at by Paul Clapham