[code type=java5]import org.apache.commons.digester.*;
import java.io.*;
import java.net.URL;
public class XMLParseEx {
public XMLParseEx(){
}
public Bean getXMLData(){
Bean bean = new Bean();
try {
URL returnURL = new URL("//want URL");
BufferedReader in = new BufferedReader(
new InputStreamReader(
returnURL.openStream()));
Digester digester = new Digester();
digester.setValidating( false );
digester.addObjectCreate( "member", Bean.class );
digester.addBeanPropertySetter( "member/user/name", "name" );
digester.addBeanPropertySetter( "member/user/id", "id" );
digester.addBeanPropertySetter( "member/user/phone", "phone" );
digester.addBeanPropertySetter( "member/user/email", "email" );
bean = (Bean)digester.parse(in);
System.out.println(bean.getName());
System.out.println(bean.getId());
System.out.println(bean.getPhone());
System.out.println(bean.getEmail());
} catch( Exception exc ) {
exc.printStackTrace();
}
return bean;
}
}[/code]
참조: Jakarta Digester
http://jakarta.apache.org/commons/digester/commons-digester-1.7/docs/api/
2007년 7월 24일 화요일
jakarta Digester를 이용한 URL XML Parsing..
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기