2011-01-10 113 views
0

我有這個RSS提要解析包含幾個標籤。我能夠檢索除了description標籤節點以外的所有值(子元素)。請找RSS低於飼料android dom解析器問題

<fflag>0</fflag> 
<tflag>0</tflag> 
<ens1:org>C Opera Production</ens1:org> 
− 
<description> 
<p>Opera to be announced</p> 

<p>$15 adults/$12 seniors/$10 for college students<span style="white-space: pre;"> </span></p> 
</description> 

,我使用這個代碼是

StringBuffer descriptionAccumulator = new StringBuffer(); 

else if (property.getNodeName().equals("description")){ 
        try{ 
         String desc = (property.getFirstChild().getNodeValue()); 
         if(property.getNodeName().equals("p")){ 
          descriptionAccumulator.append(property.getFirstChild().getNodeValue()); 
         } 
        } 
        catch(Exception e){ 
         Log.i(tag, "No desc"); 
        } 
else if (property.getNodeName().equals("ens1:org")){ 
       try{ 

         event.setOrganization(property.getFirstChild().getNodeValue()); 
         Log.i(tag,"org"+(property.getFirstChild().getNodeValue())); 
        } 
        catch(Exception e){ 

        } 
else if (property.getNodeName().equals("area")||property.getNodeName().equals("fflag") || property.getNodeName().equals("tflag") || property.getNodeName().equals("guid")){ 
        try{ 
         //event.setOrganization(property.getFirstChild().getNodeValue()); 
         Log.i(tag,"org"+(property.getFirstChild().getNodeValue())); 
        } 
        catch(Exception e){ 

        } 
else if(property.getNodeName().equals("p") || property.getNodeName().equals("em") || property.getNodeName().equals("br") || property.getNodeName().startsWith("em") || property.getNodeName().startsWith("span") || property.getNodeName().startsWith("a") || property.getNodeName().startsWith("div") || property.getNodeName().equals("div") || property.getNodeName().startsWith("p")){ 
        descriptionAccumulator.append(property.getFirstChild().getNodeValue()); 
        descriptionAccumulator.append("."); 
        System.out.println("description added:"+descriptionAccumulator); 
        Log.i("Description",descriptionAccumulator+property.getFirstChild().getNodeValue()); 


       } 

我試圖捕捉<description>標籤,但該力的值工作了,所以我嘗試使用所有常見的HTML格式化標籤,但仍然沒有出路。使用任何其他解析器不是一個選項。有人可以幫我解決這個問題。謝謝

回答

1

我相信smth與rss xml是錯誤的。例如,檢查StackOverflow rss feed返回的xml是什麼。特別要注意節點內容的外觀如何 - 它內部沒有子節點xml節點,只有純xml轉義的文本。所以如果在你的情況下是可以接受的 - 花費在適當的rss xml代上,而不是在修復後果。

0

你正在解析它爲xml,所以描述標籤沒有字符串值,它有多個孩子。您可能會嘗試獲取描述節點並將其打印爲兒童。請參閱LSSerializer以打印到XML。