Java XML
XStream vs Castor for XML serialization
Comparing Java Data Binding Tools
http://www.ibm.com/developerworks/xml/library/x-databdopt2/
http://bdoughan.blogspot.com/2010/10/how-does-jaxb-compare-to-xstream.html
다중 티어에서 XML 프로그래밍하기: 중간 티어에서 XML을 사용하여 성능과 충실도를 개선하고 개발을 용이하게 한다.
다중 티어에서 XML 프로그래밍 하기, Part 2: XML 데이터베이스 서버를 활용하는 효과적인 Java EE 애플리케이션 작성
http://bdoughan.blogspot.com/2010/10/how-does-jaxb-compare-to-xstream.html
SAX
http://proneer.tistory.com/entry/XMLSAX-LexicalHandler-Programming
Caster
http://castor.org/xml-framework.html
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import junit.framework.TestCase;
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.ValidationException;import com.nhncorp.moca.rcv.sample.job.GetMaxMovieInfoForDate;
public class CasterTest extends TestCase {
public void testCaster() throws IOException, MarshalException, ValidationException{
// Create a File to marshal to
GetMaxMovieInfoForDate period = new GetMaxMovieInfoForDate();
period.setSdate("20080428");
period.setEdate("20080428");
FileWriter writer = new FileWriter("test.xml");
Marshaller.marshal(period, writer);
}
public void testCaster2() throws IOException, MarshalException, ValidationException{
// Create a File to marshal to
GetMaxMovieInfoForDate period = new GetMaxMovieInfoForDate();
period.setSdate("20080428");
period.setEdate("20080428");
List<GetMaxMovieInfoForDate> list = new ArrayList<GetMaxMovieInfoForDate>();
list.add(period);
list.add(period);
FileWriter writer = new FileWriter("testList.xml");// Marshal the person object
Marshaller.marshal(list, writer);
}
public void testCaster3() throws IOException, MarshalException, ValidationException{
// Create a File to marshal to
Map<String,String> period = new HashMap<String,String>();
period.put("sdate","20080428");
period.put("edate","20080428");
FileWriter writer = new FileWriter("testMap.xml");
// Marshal the person object
Marshaller.marshal(period, writer);
}
}
XmlBeans
JiBX
JiBX 1.2, Part 1: Java 코드를 XML 스키마로 변환
XStream
http://markmail.org/message/kyg2rpbe23pjrvo7
XStream is an XML serialization library, not a data binding library. Therefore, it has limited namespace support. As such, it is rather unsuitable for usage within Web services.
import java.util.HashMap;
import java.util.Map;import junit.framework.TestCase;
import com.nhncorp.moca.rcv.sample.job.GetMaxMovieInfoForDate;
import com.thoughtworks.xstream.XStream;public class XStreamTest extends TestCase {
public void testXStream(){
XStream xstream = new XStream();
GetMaxMovieInfoForDate period = new GetMaxMovieInfoForDate();
period.setSdate("20080428");
period.setEdate("20080428");
xstream.alias("period", GetMaxMovieInfoForDate.class);
String result = xstream.toXML(period);
System.out.println(result);
}
public void testXStreamMap(){
XStream xstream = new XStream();
Map<String,String> period = new HashMap<String,String>();
period.put("sdate","20080428");
period.put("edate","20080428");
String result = xstream.toXML(period);
System.out.println(result);
}}
StAX
Streaming API for XML (StAX) . JSR-173에 기초 JAXP 1.4의 일부분
SAX는 이벤트 핸들러가 parser로 부터 event를 받는 것이라서 사용자는 call back 메소드를 통해서만 이를 처리할 수 있다.
어플리케이션 코드가 그것을 당겨서 받아올수 있다는 것. (pull-based approach) parsing process의 control을 직접 유지할 수 있다.
StAX'ing up XML, Part 1: An introduction to Streaming API for XML (StAX)
참조구현체: http://stax.codehaus.org/
http://rezarahim.blogspot.com/2010/05/chunking-out-big-xml-with-stax-and-jaxb.html
JDOM
JDOM : JAXP의 DOM 트리가 프로그래밍 언어에 독립적으로 정의되었기 되어서 Java언어에서 다루기가 자연스럽지 못하다는 단점이 있음. JDOM은 좀더 자바 언어에 최적화된 DOM 트리를 구성.
http://blog.daum.net/sadest/15853340?srchid=BR1http%3A%2F%2Fblog.daum.net%2Fsadest%2F15853340
Sample1
http://www.jdom.org/docs/apidocs/org/jdom/input/SAXBuilder.html
public static Document getDocument(String xmlPath) throws Exception {
InputStream in = null;
if (xmlPath.indexOf("<?") < 0) { // 경로가 입력된 경우
in = new FileInputStream(xmlPath);
} else { // XML String이 입력된 경우
in = new ByteArrayInputStream(xmlPath.getBytes());
}
SAXBuilder builder = new SAXBuilder(false);
Document configDoc = builder.build(in);
in.close();
return configDoc;
}
JAXP
abstraction layer
javax.xml.parsers는 SAXParserFactory와 DocumentBuilderFactory 제공
Simple XML Parsing with SAX and DOM
Sample - SAX
http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/parsers/SAXParserFactory.html
http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/parsers/SAXParser.html
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
parser.parse(filename, new DefaultHandler());
Sample - DOM
http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/parsers/DocumentBuilderFactory.html
http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/parsers/DocumentBuilder.html
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(filename);
Sample - XSLT 프로세서 생성 예제
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer( new SAXSource(new InputSource(stylesheetFile)));
transformer.transform( new SAXSource(new InputSource(XMLFilename)), new StreamResult(resultFilename));
JAXB
http://blog.naver.com/waitzero/70026744317
[XML] JAXB를 이용하여 스키마에서 bean추출하기
[JAXB] JAXB Annotation 설명~ Part. 1
[JAXB] JAXB Annotation 설명~ Part. 2
http://weblogs.java.net/blog/2005/09/30/using-jaxb-20s-xmljavatypeadapter
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1.9</version>
</dependency>
History
Last edited on 02/07/2011 14:32 by benelog
Comments (0)