当我使用SAX解析这个XML时,我不知道如何通过三个不同的"rel“属性获得这三个"link”标记的href属性值。
<entry>
<title>ahbei</title>
<link href="http://api.douban.com/people/1000001" rel="self" />
<link href="http://www.douban.com/people/ahbei/" rel="alternate" />
<link href="http://img3.douban.com/icon/u1000001-20.jpg" rel="icon" />
<uri>http://api.douban.com/people/1000001</uri>
</entry>我无法从这个代码中得到"http://img3.douban.com/icon/u1000001-20.jpg“。
public void startElement(String uri, String localName, String qName,
Attributes atts) throws SAXException {
if (localName.equals("link") && (atts.getValue("rel") == "icon")) // (*)
{
NowState = DBU_icon_url;
DouBanUser.setIcon(atts.getValue(0));
return;
}
}谢谢。
更改"if (localName.equals("link") && (atts.getValue("rel") == "icon"))“=> "if (localName.equals("link") && atts.getValue("rel").equals("icon"))”
发布于 2011-02-28 13:48:09
我想这能解决你的问题。
NodeList link = elementW.getElementsByTagName("link");
int getLinkCount = link.getLength();
Element elementLink;
if (getLinkCount != 0) {
for (int i = 0; i < getLinkCount; i++) {
elementLink = (Element) Link.item(i);
// Here you can get these three links.
}
}https://stackoverflow.com/questions/5142088
复制相似问题