일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- jQuery
- sencha touch
- JDOM
- Android
- iBATIS
- node.js
- Eclipse
- appspresso
- ibsheet
- 전자정부프레임워크
- oracle
- jsr 296
- MySQL
- Ajax
- MFC
- GPS
- dock
- JSON
- 선택적조인
- WebLogic
- phonegap
- Google Map
- PHP
- rowspan
- swingx
- tomcat
- 가우스
- PLSQL
- Struts
- Spring
Archives
- Today
- Total
Where The Streets Have No Name
JDom - xml파일 생성 본문
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
public class CdrXmlDemo1 {
public static void main(String[] args) {
Element root = new Element("cdr");
Element message = new Element("message");
root.addContent(message);
Element messageId = new Element("message-id");
messageId.setText("111222333");
message.addContent(messageId);
Element from = new Element("from");
from.setText("8222112517");
message.addContent(from);
Element to = new Element("to");
to.setText("8222112515");
message.addContent(to);
Element description = new Element("description");
description.setText("MM1_notification.REQ");
message.addContent(description);
Element msc = new Element("msc");
message.addContent(msc);
Element pduData = new Element("pdu-data");
msc.addContent(pduData);
Document doc = new Document(root);
// serialize it into a file
try {
FileOutputStream out = new FileOutputStream("msc.xml");
XMLOutputter serializer = new XMLOutputter();
Format f = serializer.getFormat();
f.setEncoding("UTF-8");
f.setIndent(" ");
f.setLineSeparator("\r\n");
f.setTextMode(Format.TextMode.TRIM);
serializer.setFormat(f);
serializer.output(doc, out);
out.flush();
out.close();
} catch (IOException e) {
System.err.println(e);
}
}
}