250x250
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- SpringBoot
- error
- spring
- Open Source
- Core Java
- ubuntu
- Spring Boot
- Docker
- IntelliJ
- JDBC
- Exception
- MySQL
- 설정
- myBatis
- oracle
- 오픈소스
- Python
- STS
- Source
- JavaScript
- maven
- Eclipse
- jpa
- 문서
- PostgreSQL
- Tomcat
- MSSQL
- git
- AJAX
- Thymeleaf
Archives
- Today
- Total
헤르메스 LIFE
[Source] Create Xml File Demo 본문
728x90
출처 : http://www.tutorialspoint.com/java_xml/java_jdom_create_document.htm
package com.file .utils;
import java. io.IOException ;
import org. jdom.Attribute ;
import org. jdom.Document ;
import org. jdom.Element ;
import org. jdom.output .Format;
import org. jdom.output .XMLOutputter;
public class CreateXmlFileDemo {
public static void main( String[] args ) {
try {
// root element
Element carsElement = new Element ("cars") ;
Document doc = new Document (carsElement) ;
// supercars element
Element supercarElement = new Element ("supercars") ;
supercarElement.setAttribute (new Attribute("company" , "Ferrari" ));
// supercars element
Element carElement1 = new Element ("carname") ;
carElement1.setAttribute (new Attribute("type" , "formula one" ));
carElement1.setText ("Ferrari 101") ;
Element carElement2 = new Element ("carname") ;
carElement2.setAttribute (new Attribute("type" , "sports" ));
carElement2.setText ("Ferrari 202") ;
supercarElement.addContent (carElement1) ;
supercarElement.addContent (carElement2) ;
doc.getRootElement ().addContent (supercarElement) ;
XMLOutputter xmlOutput = new XMLOutputter ();
// display ml
xmlOutput.setFormat (Format.getPrettyFormat ());
xmlOutput.output (doc, System.out );
} catch (IOException e) {
e.printStackTrace ();
}
}
}
결과
<?xml version="1.0" encoding="UTF-8"?> <cars> <supercars company="Ferrari"> <carname type="formula one">Ferrari 101</carname> <carname type="sports">Ferrari 202</carname> </supercars> </cars> |
728x90
'Core Java' 카테고리의 다른 글
[Source] XML 만들기 (0) | 2020.12.20 |
---|---|
[Source] XML 파싱 (0) | 2020.12.20 |
[Source] DOM4j Modify XMLDemo (0) | 2020.12.20 |
[Source] XPatharserDemo (0) | 2020.12.20 |
[HttpURLConnection] jsp 파일의 실행 (0) | 2020.12.17 |