更改包名称时出现奇怪的解析问题

时间:2013-07-23 05:55:57

标签: android android-xml android-parser

更改应用程序的主程序包名称时,我遇到了一个奇怪的xml解析问题。更改后一切都出错了,我已经发现从web解析的文本就像垃圾数据一样。我已经检查了RSS解析,我解析数据,但它工作正常。我的共享偏好不工作,也有mysql数据库的问题。我附加了屏幕截图(它是一个网格视图来显示新闻标题)。请看一下。我还附加了解析xml的代码。任何帮助将不胜感激。谢谢你提前......

enter image description here

public static void parse() { //method to parse XML feeds

    URL url;

    try {

        url = new URL(urls);

        HttpURLConnection conn = (HttpURLConnection) url.openConnection();

        if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) {

            DocumentBuilderFactory dbf = DocumentBuilderFactory
                    .newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc;
            doc = db.parse(url.openStream());
            doc.getDocumentElement().normalize();

            NodeList itemLst = doc.getElementsByTagName("item");

            nl = doc.getElementsByTagName(KEY_HEAD);

            Description = new String[itemLst.getLength()];// ........
            Title = new String[itemLst.getLength()];
            Tit = new String[itemLst.getLength()];
            Tit2 = new String[itemLst.getLength()];
            Desc = new String[itemLst.getLength()];
            Desc2 = new String[itemLst.getLength()];
            image = new String[itemLst.getLength()];

            for (int i = 0; i < itemLst.getLength(); i++) {

                Node item = itemLst.item(i);
                if (item.getNodeType() == Node.ELEMENT_NODE) {
                    Element ielem = (Element) item;
                    NodeList title = ielem.getElementsByTagName("title");
                    NodeList date = ielem.getElementsByTagName("pubDate");
                    NodeList description = ielem
                            .getElementsByTagName("description");
                    Tit[i] = title.item(0).getChildNodes().item(0)
                            .getNodeValue();

                    Desc[i] = description.item(0).getChildNodes().item(0)
                            .getNodeValue();



                    Tit2[i] = Translate.title(Tit[i]);
                    Desc2[i] = Translate.description(Desc[i]);






                    if (Headlines.headflag == "malayalam") {
                        Desc2[i] = Desc2[i].replace("read more", "IqSpX�");
                    }
                    Title[i] = Tit2[i];
                    if (Desc2[i].contains("<img ")) {
                        String img = Desc2[i].substring(Desc2[i]
                                .indexOf("<img "));
                        String cleanUp = img.substring(0,
                                img.indexOf(">") + 1);
                        img = img.substring(img.indexOf("src=") + 5);
                        int indexOf = img.indexOf("'");
                        if (indexOf == -1) {
                            indexOf = img.indexOf("\"");
                        }
                        img = img.substring(0, indexOf);

                        // setImgLink(img);
                        if (Headlines.headflag == "malayalam") {
                            String img2 = img.replace("files",
                                    "files/imagecache/android_320");
                            Description[i] = Desc2[i].replace(img, img2);
                            image[i] = img2;
                        }

                        else {
                            String img2 = img.replace("files",
                                    "files/imagecache/android_1_img");
                            Description[i] = Desc2[i].replace(img, "");
                            image[i] = img2;
                        }
                    } else {
                        Description[i] = Desc2[i];
                    }

                }

            }

        }

    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (DOMException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

1 个答案:

答案 0 :(得分:1)

尝试在所有课程中搜索旧包裹名称