<description>
SEBI : Decision taken by a listed investment company to dispose of a part of its
investment is not “price sensitive information” within meaning of SEBI
(Prohibition of Insider Trading) Regulations, 1992<br>;
By <b> [2011] 15 taxmann.com 229 (SAT)</b>
</description>
후 SAX를 사용하여 XML을 구문 분석. 내가 할 수 구문 분석 해요 전에이 내 핸들 클래스 코드 <br>
오류이 내가 <code><br></code> 후 데이터를 파싱 할 XML입니다 <br>
후 구문 분석 할 수 <br>
아니라 :
package com.exercise;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class RSSHandler extends DefaultHandler {
final int state_unknown = 0;
final int state_title = 1;
final int state_description = 2;
final int state_link = 3;
final int state_pubdate = 4;
int currentState = state_unknown;
RSSFeed feed;
RSSItem item;
boolean itemFound = false;
RSSHandler(){
}
RSSFeed getFeed(){
return feed;
}
@Override
public void startDocument() throws SAXException {
// TODO Auto-generated method stub
feed = new RSSFeed();
item = new RSSItem();
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// TODO Auto-generated method stub
if (localName.equalsIgnoreCase("item")){
itemFound = true;
item = new RSSItem();
currentState = state_unknown;
}
else if (localName.equalsIgnoreCase("title")){
currentState = state_title;
}
else if (localName.equalsIgnoreCase("description")){
currentState = state_description;
}
else if (localName.equalsIgnoreCase("link")){
currentState = state_link;
}
else if (localName.equalsIgnoreCase("pubdate")){
currentState = state_pubdate;
}
else{
currentState = state_unknown;
}
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
// TODO Auto-generated method stub
currentState = state_unknown;
if (localName.equalsIgnoreCase("item")){
feed.addItem(item);
}
}
@Override
public void characters(char ch[], int start, int length)
throws SAXException {
//super.characters(ch, start, length);
// TODO Auto-generated method stub
StringBuilder buf=new StringBuilder();
if (buf!=null) {
for (int i=start; i<start+length; i++) {
buf.append(ch[i]);
}
String strCharacters=buf.toString();
if (itemFound==true){
// "item" tag found, it's item's parameter
switch(currentState){
case state_title:
item.setTitle(strCharacters);
break;
case state_description:
item.setDescription(strCharacters); //here data coming
break;
case state_link:
item.setLink(strCharacters);
break;
case state_pubdate:
item.setPubdate(strCharacters);
break;
default:
break;
}
}
else{
// not "item" tag found, it's feed's parameter
switch(currentState){
case state_title:
feed.setTitle(strCharacters);
break;
case state_description:
feed.setDescription(strCharacters);
break;
case state_link:
feed.setLink(strCharacters);
break;
case state_pubdate:
feed.setPubdate(strCharacters);
break;
default:
break;
}
}
currentState = state_unknown;
}
}
}
에 초기화하려고합니다. 'br'는 스스로 폐쇄해야합니다. –