Language/Java

[JAXB] XSD 정의 및 Java 파일 생성

OIZTLOMO 2012. 1. 30. 13:50


1. datasets.xsd 정의

<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"

targetNamespace="http://www.example.org/datasets" elementFormDefault="qualified" xmlns:xs="http://www.example.org/datasets">


    <xsd:element name="datasets">

     <xsd:complexType>

     <xsd:sequence>

     <xsd:element name="dataset" type="xs:DatasetComplexType" maxOccurs="unbounded" minOccurs="1"></xsd:element>

     </xsd:sequence>

     </xsd:complexType>

    </xsd:element>

    <xsd:complexType name="DatasetComplexType">

     <xsd:sequence>

     <xsd:element name="item" maxOccurs="unbounded" minOccurs="1">

     <xsd:complexType>

     <xsd:attribute name="name" type="xsd:string" use="required"></xsd:attribute>

     <xsd:attribute name="value" type="xsd:string" use="required"></xsd:attribute>

                    <xsd:attribute name="type" type="xsd:string"></xsd:attribute>

                    <xsd:attribute name="trim" default="Y" type="xsd:string"></xsd:attribute>

     <xsd:attribute name="offset" type="xsd:int" default="0"></xsd:attribute>

     <xsd:attribute name="length" type="xsd:int" default="0"></xsd:attribute>

     <xsd:attribute name="parsedvalue" type="xsd:string"></xsd:attribute>

     </xsd:complexType>

     </xsd:element>

     </xsd:sequence>

     <xsd:attribute name="name" type="xsd:string" use="required"></xsd:attribute>

     <xsd:attribute name="type" type="xsd:string" use="required"></xsd:attribute>

     <xsd:attribute name="scope" type="xsd:string" use="optional"></xsd:attribute>

     <xsd:attribute name="offset" type="xsd:int" default="0"></xsd:attribute>

     <xsd:attribute name="length" type="xsd:int" default="0"></xsd:attribute>

        <xsd:attribute name="itemcount" type="xsd:int" default="0"></xsd:attribute>

        <xsd:attribute name="itemlength" type="xsd:int" default="0"></xsd:attribute>

    </xsd:complexType>

</xsd:schema>


# eclipse XML Editor View




2. Java 파일 생성. (xjc 명령어 실행 - 참조: JAXB Install and xsd Compile )

예> xjc -p com.test.jaxb.xml datasets.xsd -d .


./com/test/jaxb/xml 디렉토리 아래에 다음과 같은 Java 소스파일이 생성 됨.


- DatasetComplexType.java

- Datasets.java

- ObjectFactory.java

- package-info.java