XML解析以获取完整的文本

时间:2011-05-02 08:19:44

标签: android

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

当我在andorid

中的xml解析中看到来自字符函数的currentValues时

然后它只显示全文的一些字符,解析器跳过剩余的文本

所以我需要全文,无论这个字符有多少。

例子--->原始文本是 - >“嗨,你好,不管怎么样,你做什么.....继续做很多行”

但我只有10或20个字符或类似的东西,但不是全文 请回复

xml文件

<item>
    <title>Ideologue : Pandit Deendayal Upadhyaya (1916-1968)  </title>
        <description>
            <text><![CDATA[<p style="font-size: 1.1em;"><span style="color: #ff6600;">
<em>Pandit Deendayal Upadhyaya was the leader of
     the Bharatiya Jana Sangh from 1953 to
     1968. A profound philosopher, organiser par excellence and a leader
     who maintained the highest standards
     of personal integrity, he has been the
     source of ideological guidance and
     moral inspiration for the BJP since
     its inception. His treatise Integral
     Humanism, which is a critique of both
     communism and capitalism, provides a
     holistic alternative perspective for
     political action and statecraft
     consistent with the laws of Creation
     and the universal needs of the human
     race.</em></span><br /><br
     /><strong><span style="color: #990000; font-size: 1.2em;"><span
     style="text-decoration: underline;">A
     Short
     Biography</span></span></strong><br/><br />Pandit Deendayal Upadhyaya was
     born on Monday September 25, 1916, in
     the sacred region of Brij in the
     village of Nagla Chandraban in Mathura
     District . His father was a well known
     astrologer. An astrologer who studied
     his horoscope predicted that the boy
     would become a great scholar and
     thinker, a selfless worker, and a
     leading politician - but that he would
     not marry. While at Bhatpur tragedy
     struck the family, he lost his brother
     to illness in 1934. He later went to
     high school in Sikar. Maharaja of
     Sikar gave Pandit Upadhyaya a gold
     medal, Rs. 250 for books and a monthly
     scholarship of Rs.10.<br /><br/>Pandit Upadhyaya passed his
     Intermediate exams with distinction in
     Pilani and left to Kanpur to pursue
     his B.A. and joined the Sanatan Dharma
     college. At the instance of his friend
     Shri. Balwant Mahashabde, he joined
     the RSS in 1937. In 1937 he received
     his B.A. in the first division. Pandit
     Upadhyaya moved to Agra to pursue
     M.A.<br /><br />Here he joined forces
     with Shri. Nanaji Deshmukh and Shri.
     Bhau Jugade for RSS activities. Around
     this time Rama Devi, a cousin of
     Deendayalji fell ill and she moved to
     Agra for treatment. She passed away.
     Deendayalji was very depressed and
     could not take the M.A. exams. His
     scholarships, received earlier from
     Maharajaj of Sikar and Shri. Birla
     were discontinued.<br /><br />At the
     instance of his aunt he took a
     Government conducted competitive
     examination in dhoti and kurta with a
     cap on his head, while other
     candidates wore western suits. The
     candidates in fun called him
     "Panditji" - an appellation millions
     were to use with respect and love in
     later years. Again at this exam he
     topped the list of selectees. Armed
     with his Uncle's permission he moved
     to Prayag to pursue B.T. and at Prayag
     he continued his RSS activites. After
     completion of his B.T., he worked
     full-time for the RSS and moved to
     Lakhimpur District in UP as an
     organizer and in 1955 became the
     Provincial Organizer of the RSS in
     UP.<br /><br />He established the
     publishing house 'Rashtra Dharma
     Prakashan' in Lucknow and launched the
     monthly magazine 'Rashtra Dharma' to
     propound the principles he held
     sacred. Later he launched the weekly
     'Panchjanya' and still later the daily
     'Swadesh'. In 1950, Dr. Syama Prasad
     Mookerjee, then Minister at the
     Center, opposed the Nehru-Liaquat pact
     and resigned his Cabinet post and
     joined the opposition to build a
     common front of democratic forces.
     Dr.Mookerjee sought Shri. Guruji's
     help in organizing dedicated young men
     to pursue the work at the political
     level.<br /><br />Pandit Deendayalji
     convened on September 21, 1951 a
     political convention of UP and founded
     the state unit of the new party,
     Bharatiya Jana Sangh. Pandit.
     Deendayalji was the moving spirit and
     Dr. Mookerjee presided over the first
     all-India convention held on October
     21, 1951.<br /><br />Pandit
     Deendayalji's organizing skills were
     unmatched. Finally came the red letter
     day in the annals of the Jana Sangh
     when this utterly unassuming leader of
     the party was raised to the high
     position of President in the year
     1968. On assuming this tremendous responsibility Deendayalji went to the
     South with the message of Jana Sangh.
     On the dark night of February 11,
     1968, Deendayal Upadhyaya was
     fiendishly pushed into the jaws of
     sudden death.</p>]]></text>
         </description>
             <author> deepa@tetrain.com (Administrator)</author>
             <pubDate>Wed, 25 Aug 2010 07:08:26 GMT</pubDate>
         </item>

1 个答案:

答案 0 :(得分:2)

对于单个元素,可能会多次调用characters()。如果您希望将数据作为单个连续字符串,则需要连接结果。