2011-02-28 16 views
0

このXMLを解析するためにSAXを使用すると、3つの異なる "rel"タグでこの3つの "link"タグのhref属性値を取得する方法がわかりません。属性。同じタグと複数の属性を持つSAX parse xmlの使用方法

<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").equals("icon"))"

+0

*このコードは*あなたが取得したものですか? –

+0

'(localName.equals(" link ")&& atts.getValue(" rel ")。equals(" icon "))' –

+0

3番目のリンクのhref値を取得します。 – Xhinking

答えて

0


変更 "if (localName.equals("link") && (atts.getValue("rel") == "icon"))" 。

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. 
} 
} 
+0

ありがとうございますSaurabh! – Xhinking

関連する問題