更改应用程序的主包名称时,我遇到了一个奇怪的 xml 解析问题。更改后一切都出错了,我发现从网络解析的文本就像垃圾数据。我已经检查了从中解析数据的 RSS 提要,但它工作正常。而且我的共享偏好不起作用,mysql 数据库也有问题。我附上了屏幕截图(它是显示新闻标题的网格视图)。请看一下。我还附上了解析xml的代码。任何帮助将不胜感激..在此先感谢...
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();
}
}