2013-03-15 62 views
0
當我把

的的getText()方法刪除標記名稱,獲取InoutStream我想從XmlPullParser

inputStream = new URL("http://www.hindu.com/rss/01hdline.xml").openStream(); 
InputStreamReader isr = new InputStreamReader(inputStream); 

內,

xpp.setInput(isr); // i am getting Text in every logs output 

但是,當,當我把一些XML部分來自這個XML,

<item> 
<category/> 
<link> 
http://www.hindu.com/2011/06/30/stories/2011063063980100.htm 
</link> 
<title>Talk of drift, corruption is propaganda: Manmohan</title> 
<description></description> 
<pubDate>Thu, 30 Jun 2011</pubDate> 
</item> 

it is working properly , means i am not getting Text in every log's output . like 
03-15 06:08:35.199: I/rss(2354): TEXT 
03-15 06:08:35.199: I/channel(2354): TEXT 
03-15 06:08:35.209: I/The Hindu - Front Page(2354): TEXT 
03-15 06:08:35.209: I/title(2354): TEXT 
03-15 06:08:35.228: I/http://www.hindu.com/(2354): TEXT 
03-15 06:08:35.228: I/link(2354): TEXT 
03-15 06:08:35.249: I/The Internet edition of The Hindu, India's national newspaper(2354): TEXT 

這是我的,xmlPullParser.getText()方法,

if(eventType == XmlPullParser.TEXT) 
       { 
        Log.i(xpp.getText(), "TEXT") ; 
       } 

回答

0

只是做這樣的,

if (eventType == XmlPullParser.START_TAG) 
{ 
    if(xpp.getName().equalsIgnoreCase("item")) 
    { 
    eventType = xpp.next(); 

    if (eventType == XmlPullParser.TEXT) 
    { 
     Log.i(xpp.getText(), "TEXT") ; 
    } 
    } 
} 

所以每次你必須檢查並做類似這樣的標籤....