1. jdom.jar를 web-inf/lib 밑에 복사 한후 이클립스에서 빌드패스로 설정한다.
2. output 으로 나오는 XML 형태
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>media4th</title>
<description>web agency</description>
<link>http://www.media4th.co.kr</link>
</channel>
</rss>
3. 소스 코드
Element eleRoot = new Element("rss");
eleRoot.setAttribute(new Attribute("version", "2.0"));
Document document = new Document(eleRoot);
Element eleChannel = new Element("channel");
Element eleTitle = new Element("title");
Element eleDescription = new Element("description");
Element eleLink = new Element("link");
eleTitle.setText(feed.getTitle());
eleDescription.setText(feed.getDescription());
eleLink.setText(feed.getLink());
eleChannel.addContent(eleTitle);
eleChannel.addContent(eleDescription);
eleChannel.addContent(eleLink);
eleRoot.addContent(eleChannel);
try{
XMLOutputter serializer = new XMLOutputter();
Format prettyFormat = Format.getPrettyFormat();
serializer.setFormat(prettyFormat);
System.out.println("At this point we would serialize the feed " + feed.getTitle() + " to a file. For now we are just going to write it to the console.");
serializer.output(document, System.out);
}catch(IOException e){
System.out.println("Error saving feed");
}
최근 덧글