I've seen quite a few posts about this, but actually I did not get any to work. I am building a simple TV guide android application. I simply Use RSS from a tvprofil.net to show whats on TV today. The problem is, I do not know how to Parse CDATA in XML. I am using some standard parser with DOM... at least I think so..
This is a bit of XML:
now, this is my main app:
and the parser class:
there is one more class for Single menu item.. but I think it's irrelevant in this case. Now, I'd just like to see no HTML tags after parsing it and dealing with CDATA... Anyone got idea about this one?
If you're looking for an element which is in a namespace (which you are) then don't use the getElementsByTagName method, use the getElementsByTagNameNS method. Its parameters are namespace URI and element name.
 First, you're using a parser default to Namespace non-aware. That's by default. If you change you mind later to prefer a namespace-aware parser, set it at the factory level by adding this.
 With your namespace non-aware parser, the prefix _must_ exactly match that of the input rss. That is a big drawback as one day or another that prefix can be changed (that's the idea of the prefix itself which is quite arbitrary). So in this sense it is fine to use KEY_DESC as such with getElementsByTagName() method again as such.
 The problem is that you use getFirstChild to access to the data. That the conditional should take care of that fact in the case of a CDATA section.
[2.1] It is not the only way to get access to the text content. You can do directly with the elem itself (which is itself always an ELEMENT_NODE), like this under the condition that the implementation supports dom level 3 recommendation --- unfortunately, it looks like it was not yet on the Android at some time, thing can be changed since and this rests to be ascertained if you decide to use it.
Now, I do not know if I am so stupid, or it's becouse I never have dealt myself with parsing, but, still, even I changed those few lines I can't set it to work. It still displays <title> and <pubDate> as it should, but the <description>, the one I need the most is still missing. I kneel before you, and beg you.... if you have any spare time, please fix my code so I can just use it directly... I tried so many things, but nothing seams to work. Honestly, I am on this same point for more than a week.
Joined: Jan 18, 2011
...even I changed those few lines I can't set it to work.
I suppose you faithfully represent the rss up to the detail of the prefix "content". The only plausible explanation is that dbf is namespace aware. If that is the case, that is quite ok, you can deal with it. But, for the first instance, I want to ascertain this fact by modifying least possible lines. Once this is verified, you can deal with the same problem with namespace proper: and that is not very complicated to improve in that front. That's for the future.
[3.1] Just a side-note to let another issue in peace. You've set coalescing to true. That should in principle have taken care of the test condition Node.CDATA_SECTION_NODE as the same node would then be treated as a TEXT_NODE. That is another possible hint that the parser might just have been a namespace aware parser for that to fail to getting the correct result.
[3.2] I suggest as an intermediate step of verifying what is wrong. Add this just after the setting up of dbf.
And then proceed with the same code at present. Try it and see what results.
I have the same code for parsing RSS XML feed and works very nice! Thanks to all people who helped with this because I had the same problem as Igor Mandic.
But now I have a problem that I can't solve it.
I want to show the description ONLY in SingleMenuItemActivity.class because this code show you the description in Main and SingleMenuItemActivity .
How can I do this? I tried to delete the KEY_DESC in the ListAdapter but not works. Deleting map.put(KEY_DESC, parser.getValue(e, KEY_DESC)); too, but doesn't works.
Any idea? Thanks to all ^^
subject: Parse CDATA with XMLParser in this specific case for Android