开发者

Some Quotes and apostrophes don't parse correctly

Okay, first, I'm a noob at android programming. I have taken some Java, but I'm still learning (aren't we all). I'm trying to take the source code form here and have it read an RSS feed correctly. Currently I have 2 problems. I'll just state the first one and then post another post for the second.

One the RSS feed is displayed on my device, it doesn't include all of the details (description). When I load the feed through my browser I notice that some of the quotation marks and apostrophes are turned into " and '. For s开发者_运维百科ome reason this stops the parser from correctly parsing it. Any help would be greatly appreciated.


I was facing the same problem. I used UTF-8 encoding for parsing. But after making it ISO-8859-1, everything went correctly. I cant paste the complete code but just a sample for you where you can make change is as folows: My previous code for parsing was

Xml.parse(feedStream, Xml.Encoding.UTF_8, root.getContentHandler());

After that I converted it as follows:

Xml.parse(feedStream, Xml.Encoding.ISO_8859_1, root.getContentHandler());


I found out the cause of the problem. I had to setup a string buffer in the charcters method.

public void characters(char ch[] , int start, int length)
{
    if (buffering)
            buf.append(ch, start, length);

}

Once I did that, i just assigned the stringbuffer to a string in the "endelement" method when I stored my data.

public void endElement(String namespaceURI, String localName, String qName) throws SAXException
{

    String content = buf.toString();
    Log.i("RSSReader  ",currentstate +"  " + content + "]");
    switch (currentstate)
    {
        case RSS_TITLE:
                _item.setTitle(content);
                buffering = false;
            currentstate = 0;
            break;
        case RSS_LINK:
                _item.setLink(content);
                buffering = false;
            currentstate = 0;
            break;
        case RSS_DESCRIPTION:
                _item.setDescription(content);
                buffering = false;
            currentstate = 0;
            break;

    }

After that everything worked just fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜