The issue has still "new" status so either Google is just ignoring it
or they think it's a bug in my code.

I tried a little more and I experienced similar problems when fetching
XML that has encoded html inside the tags (typically RSS feeds). This
code works perfectly when running on the desktop but on android it
just refuses to give me the text after it encounters "<" in this
node:
<description>Test html chars: &lt;b&gt;v2.1&lt;/b&gt; released.</
description>

The full sample code is included below in case someone would like to
give it a try or tell me if I am missing something here!?

Desktop output:
********* RSS: Test html chars: <b>v2.1</b> released. Read about the
changes here!

Android output:
****************Test html chars:

Sample code:

      URI rssurl = URI.create("http://www.hvaerstillingen.no/docs/rss/
test.txt");
      try {
         DocumentBuilder builder =
           DocumentBuilderFactory.newInstance().newDocumentBuilder();
         Document doc = builder.parse(rssurl.toURL().openStream());

         NodeList nodes = doc.getElementsByTagName("item");
         for (int i = 0; i < nodes.getLength(); i++) {
           Element element = (Element) nodes.item(i);

           NodeList title = element.getElementsByTagName("title");
           Element line = (Element) title.item(0);


           Element descEl = (Element) element.getElementsByTagName
("description").item(0);
           Node textNode = descEl.getFirstChild();
           System.out.println("********* RSS: "+ textNode.getNodeValue
());
         }
       }
       catch (Exception e) {
          e.printStackTrace();
       }

-Christer


On 1 Des 2008, 19:54, "Xavier Mathews" <[email protected]> wrote:
> Ok Great!
>
> Xavier A. Mathews
> Student/Browser Specialist/Developer/Web-Master
> Google Group Client Based Tech Support Specialist
> Hazel Crest Illinois
> [email protected]¥[email protected]¥[email protected]
> "Fear of a name, only increases fear of the thing itself."
>
> On Mon, Dec 1, 2008 at 12:58 AM, ChisterNordvik <[email protected]> wrote:
>
> > It's been added:
> >http://code.google.com/p/android/issues/detail?id=1398
>
> > -Christer
>
> > On 1 Des, 01:55, "Xavier Mathews" <[email protected]> wrote:
> > > Same Problem Here. Post It In The Issue Tracker!
>
> > > On 11/30/2008, [email protected] <[email protected]>
> > wrote:
>
> > > > Yes, I have also encountered the same problem. Any suggestions?
>
> > > > On Nov 30, 10:53 pm, ChisterNordvik <[email protected]> wrote:
> > > >> Hi!
>
> > > >> Does anyone have a workingRSSparser with Android? I tried doing
> > > >> simple DOM parsing of the XML but the character encoding isn't handled
> > > >> properly so the norwegian characters aren't displayed. I have tried
> > > >> everything but when I get the description element I just get the text
> > > >> until the norwegian character. Any sample code of parsing
> > > >> internationalRSSfeeds would be very welcome!
>
> > > >> Here is the feed that I am having problems
> > > >> with:http://www.dagbladet.no/rss/fotball/
>
> > > >> -Christer
>
> > > >> Sample code that I started out with (have tried lots of encoding
> > > >> tricks to no avail):
>
> > > >> Feed feed = createFeed(this,
> > > >>                                         new
> > > >> java.net.URI("http://www.dagbladet.no/rss/fotball/";));
> > > >> ...
> > > >> public Feed createFeed(Context ctx, URI rssurl) {
> > > >>                 Feed feed = new Feed();
> > > >>                 try {
> > > >>                      DocumentBuilder builder =
>
> > > >>  DocumentBuilderFactory.newInstance().newDocumentBuilder();
> > > >>                      Document doc =
> > > >> builder.parse(rssurl.toURL().openStream());
>
> > > >>                      NodeList nodes =
> > doc.getElementsByTagName("item");
> > > >>                      for (int i = 0; i < nodes.getLength(); i++) {
> > > >>                        Element element = (Element) nodes.item(i);
>
> > > >>                        NodeList title =
> > > >> element.getElementsByTagName("title");
> > > >>                        Element line = (Element) title.item(0);
>
> > > >>                        String feedTitle =
> > > >> getCharacterDataFromElement(line);
> > > >>                        String url = getCharacterDataFromElement
> > > >> (element.getElementsByTagName("link").item(0));
> > > >>                        Article art = new Article();
> > > >>                        art.title = feedTitle;
> > > >>                        art.url = url;
> > > >>                        art.description = getCharacterDataFromElement
> > > >> (element.getElementsByTagName("description").item(0));
> > > >>                        feed.articles.add(art);
>
> > > >>                      }
> > > >>                    }
> > > >>                    catch (Exception e) {
> > > >>                       e.printStackTrace();
> > > >>                    }
> > > >>                    return feed;
> > > >>         }
> > > >>         public static String getCharacterDataFromElement(Node e) {
> > > >>                    Node child = e.getFirstChild();
> > > >>                    if(child == null)
> > > >>                            return "?";
> > > >>                    if (child instanceof CharacterData) {
> > > >>                      CharacterData cd = (CharacterData) child;
> > > >>                        return cd.getData();
> > > >>                      }
> > > >>                    return "?";
> > > >>                  }
>
> > > --
> > > Xavier A. Mathews
> > > Student/Browser Specialist/Developer/Web-Master
> > > Google Group Client Based Tech Support Specialist
> > > Hazel Crest Illinois
> > > [email protected]¥[email protected]¥[email protected]
> > > "Fear of a name, only increases fear of the thing itself."
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to