檢索HTML標籤我有一個XML來解析,這下面SAX解析器:從XML
給出<feed>
<feed_id>12941450184d2315fa63d6358242</feed_id>
<content> <fieldset><table cellpadding='0' border='0' cellspacing='0' style="clear :both"><tr valign='top' ><td width='35' ><a href='http://mypage.rediff.com/android/32868898' class='space' onmousedown="return enc(this,'http://track.rediff.com/click?url=___http%3A%2F%2Fmypage.rediff.com%2Fandroid%2F32868898___&service=mypage_feeds&clientip=202.137.232.113&pos=0&feed_id=12941450184d2315fa63d6358242&prc_id=32868898&rowid=674061088')" ><div style='width:25px;height:25px;overflow:hidden;'><img src='http://socialimg04.rediff.com/image.php?uid=32868898&type=thumb' width='25' vspace='0' /></div></a></td> <td><span><a href='http://mypage.rediff.com/android/32868898' class="space" onmousedown="return enc(this,'http://track.rediff.com/click?url=___http%3A%2F%2Fmypage.rediff.com%2Fandroid%2F32868898___&service=mypage_feeds&clientip=202.137.232.113&pos=0&feed_id=12941450184d2315fa63d6358242&prc_id=32868898&rowid=674061088')" >Android </a> </span><span style='color:#000000 !important;'>testing</span><div class='divtext'></div></td></tr><tr><td height='5' ></td></tr></table></fieldset><br/></content>
<action>status updated</action>
</feed>
標籤包含HTML內容,其中包含了我所需要的數據。我正在使用SAX解析器。這是我在做什麼
private Timeline timeLine; //Object
private String tempStr;
public void characters(char[] ch, int start, int length)
throws SAXException {
tempStr = new String(ch, start, length);
}
public void endElement(String uri, String localName, String qName)
throws SAXException {
if (localName.equalsIgnoreCase("content")) {
if (timeLine != null) {
timeLine.setContent(tempStr);
}
}
這個邏輯的工作原理是什麼?如果不是,我應該如何使用SAX解析器從XML中提取嵌入的HTML數據。
'timeLine'和'tempStr'從哪裏來? – 2011-01-05 09:20:30
@精英紳士編輯支持請求變量。 – 2011-01-05 09:39:49