2011-05-02 107 views
2

如何從給出的xmlXML解析,以獲取描述標籤

<item> 
      <title>All India Lawyer Conference at Lucknow </title> 
     <description> 
<text><![CDATA[<p style="text-align: center;">]]></text> 
<image>http://www.bjp.org/images/stories/kamala_2.png</image> 
<text><![CDATA[ 
<p style="text-align: center;"><span style="color: #ff6600;"><span style="font-size: 24pt;"><strong>Bharatiya Janata Party</strong><strong><em><br /><br /></em></strong></span></span></p> 
<span style="color: #008000;"><span style="font-size: 18pt;"><span style="font-family: arial black,avant garde;">&nbsp;</span></span></span> 
<p style="text-align: center;"><span style="color: #008000;"><span style="font-size: 18pt;"><strong><span style="font-family: 'arial black', 'avant garde';">All India Lawyer Conference </span></strong></span></span></p> 
<p style="text-align: center;"><span style="color: #008000;"><span style="font-size: 18pt;"><strong><span style="font-family: 'arial black', 'avant garde';">at Lucknow (Uttar Pradesh)</span></strong></span></span></p> 
<p style="text-align: center;"><span style="font-family: 'arial black', 'avant garde'; color: #008000; font-size: large;"><strong><br /></strong></span></p> 
<p style="text-align: center;"> </p> 
<p style="text-align: center;"><strong><span style="font-family: andale mono,times;"><em><span style="font-size: 14pt;"><span style="color: #ff0000;">of</span></span></em></span></strong></p> 
<p style="text-align: center;"><span style="font-family: arial black,avant garde;"><span style="font-size: 14pt;"><span style="color: #000080;"><strong>BJP President Shri Nitin Gadkari</strong></span></span></span></p> 
<p style="text-align: center;"> </p> 
<p style="text-align: center;"><span style="font-size: 12pt;"><span style="color: #ff0000;"><strong>on<br /></strong></span></span></p> 
<p style="text-align: center;"><strong><span style="font-size: 12pt;"><span style="color: #ff0000;">May 15, 2011 (Sunday)</span></span><br /></strong></p>]]></text> 
     </description> 
      <author> [email protected] (Anurag Pathak)</author> 
      <pubDate>Sun, 15 May 2011 00:00:00 GMT</pubDate> 
     </item> 

解析使用XML android系統解析描述的細節,我想所有文字,顯示粗體字母

我的編碼

@Override 
    public void startElement(String uri, String localName, String qName,Attributes attributes) throws SAXException 
    { 
     printParseInfo("startElement:", uri, localName, qName); 
     int attributesLength = attributes.getLength(); 
     for (int i = 0; i < attributesLength; i++) 
     { 
      printAttributeInfo(attributes, i); 
     } 
     currentElement = true; 
     if (localName.equals("rss")) 
     { 
      /** Start */ 
      sitesList = new SitesList(); 
     } 
    } 
    /** Called when tag closing (ex:- <name>AndroidPeople</name> -- </name>)*/ 
    @Override 
    public void endElement(String uri, String localName, String qName) throws SAXException 
    { 
     currentElement = false; 
     printParseInfo("endElement: ", uri, localName, qName); 
     /** set value */ 
     if (localName.equalsIgnoreCase("title")) 
     { 
      //Log.d("title--->",currentValue); 
      sitesList.setTitle(currentValue); 
     } 
     else 
     if(localName.equalsIgnoreCase("span")) 
     { 
      //Log.d("strong-->",currentValue); 
      sitesList.setStrong(currentValue); 
     } 
     if (localName.equalsIgnoreCase("description")) 
     { 
      //Log.d("description--->",currentValue); 
      sitesList.setDescription(currentValue); 
     } 
     else 
     if (localName.equalsIgnoreCase("author")) 
     { 
      //Log.d("Author--->",currentValue); 
      sitesList.setAuthor(currentValue); 
     } 
     else 
     if(localName.equalsIgnoreCase("pubDate")) 
     { 
      //Log.d("pubDate--->",currentValue); 
      sitesList.setPubDate(currentValue); 
     } 
     else 
     if(localName.equalsIgnoreCase("image")) 
     { 
      //Log.d("Image--->",currentValue); 
      sitesList.setImage(currentValue); 
     } 
    } 
    /** Called to get tag characters (ex:- <name>AndroidPeople</name> -- to get AndroidPeople Character) */ 
    @Override 
    public void characters(char[] ch, int start, int length) throws SAXException 
    { 
     if (currentElement) 
     { 
      currentValue = new String(ch, start, length); 
      Log.d("char-->",currentValue); 
      currentElement = false; 
     } 
    } 
+1

哪裏是你的XML? – 2011-05-02 07:19:14

+0

我怎麼可以放在這裏,當我寫它顯示爲以上文本 – 2011-05-02 07:22:35

+0

使用XML的鏈接。 – 2011-05-02 07:39:28

回答