程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> android-XML解析獲取 description tab

android-XML解析獲取 description tab

編輯:編程綜合問答
XML解析獲取 description tab

使用下面的 xml 中的 xml parsing,如何解析 description 細節?

<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>

我想把文本以粗體顯示:

@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;
        }
    }

最佳回答:


使用 XML 解析器
1. SAX
2. DOM
3. StAX

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved