將Schema檔案轉換為Java檔案
可通過xjc命令完成將schema檔案轉換為java檔案。
開啟命令控制檯,切換至專案中xsd檔案所在目錄,如E:\Eclipse\webservice\03_schema\src\schema
輸入命令:xjc -d <匯出的java檔案存放目錄> -verbose <需要轉換的xsd檔案>
如:xjc -d E:\Eclipse\webserviceimport\02 -verbose classroom.xsd
生成的Java檔案:
生成的ClassroomType.java
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2013.11.30 at 11:10:46 PM CST
//
package org.example.classroom;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for classroomType complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="classroomType">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="grade" type="{http://www.example.org/classroom}gradeType"/>
* <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <sequence maxOccurs="unbounded">
* <element name="student" type="{http://www.example.org/classroom}studentType"/>
* </sequence>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "classroomType", propOrder = {
"grade",
"name",
"student"
})
public class ClassroomType {
protected int grade;
@XmlElement(required = true)
protected String name;
@XmlElement(required = true)
protected List<StudentType> student;
/**
* Gets the value of the grade property.
*
*/
public int getGrade() {
return grade;
}
/**
* Sets the value of the grade property.
*
*/
public void setGrade(int value) {
this.grade = value;
}
/**
* Gets the value of the name property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getName() {
return name;
}
/**
* Sets the value of the name property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setName(String value) {
this.name = value;
}
/**
* Gets the value of the student property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the student property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getStudent().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link StudentType }
*
*
*/
public List<StudentType> getStudent() {
if (student == null) {
student = new ArrayList<StudentType>();
}
return this.student;
}
}
生成的java檔案還是很完備的。
---
classroom.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/classroom"
xmlns:tns="http://www.example.org/classroom"
elementFormDefault="qualified">
<xsd:include schemaLocation="student.xsd" />
<xsd:element name="classroom" type="tns:classroomType" />
<xsd:complexType name="classroomType">
<xsd:sequence>
<xsd:element name="grade" type="tns:gradeType" />
<xsd:element name="name" type="xsd:string" />
<!--如果需要生成java檔案,最好不要多重巢狀,此處改用sequence
<xsd:element name="students">
<xsd:complexType>
<xsd:sequence minOccurs="1" maxOccurs="unbounded">
<xsd:element name="student" type="tns:studentType" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
-->
<xsd:sequence minOccurs="1" maxOccurs="unbounded">
<xsd:element name="student" type="tns:studentType" />
</xsd:sequence>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="gradeType">
<xsd:restriction base="xsd:int">
<xsd:minInclusive value="2008" />
<xsd:maxInclusive value="3000" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
相關文章
- 如何將.ipynb檔案轉換為.py檔案
- Java 將Markdown檔案轉換為Word和PDF文件Java
- Linux下批量將md檔案轉換為html檔案LinuxHTML
- PDF檔案轉換為DWF檔案
- aspose word轉換pdf檔案後將pdf檔案轉換為圖片png
- Mxnet模型檔案轉換為Pb模型檔案模型
- python 將 CVS檔案轉為HTML檔案PythonHTML
- Win10系統下將excel檔案轉換為dbf檔案的方法Win10Excel
- 如何將 PowerPoint 簡報轉換為 PDF 檔案?
- office舊版本檔案轉換為新版本檔案
- ubuntu下使用sratoolkit將sra檔案轉換成fastq檔案UbuntuAST
- 如何將BigWig 檔案轉化為 bed 檔案
- RTF 批量轉換為 DOCX 檔案
- java 字串與檔案相互轉換Java字串
- WOR檔案轉換成GST檔案
- 蘋果手機如何將PDF檔案轉換為Word文件蘋果
- 將DOS批處理檔案轉換為Shell指令碼指令碼
- Json檔案轉換為Excel檔案!涉及讀檔案,時間戳轉化,寫文件JSONExcel時間戳
- 將ASD光譜儀的.asd檔案轉為文字檔案
- 表的schema 檔案
- 將bmp檔案壓縮為jpg檔案
- 如何使用python把json檔案轉換為csv檔案PythonJSON
- PDF檔案如何轉換為能編輯的CAD檔案
- 【原創】ASM下的資料檔案轉換為普通檔案ASM
- ASM 檔案與本地檔案的轉換ASM
- 把 .xyz 檔案轉換成 .ply 檔案
- 如何實現將markdown檔案實時轉換為html文件HTML
- 將檔案的行結束符由 CRLF 轉換為 LF
- 將檔案轉化為字串的方法字串
- Java 檔案換行符識別與轉換Java
- 通過反射將物件轉化為檔案,同時反向將檔案還原為物件(適用配置檔案讀寫)反射物件
- 用C#把檔案轉換為XML(轉)C#XML
- 如何將plist檔案或者陣列NSArray轉化為.json檔案?陣列JSON
- python 將檔案大小轉換為human readable 的大小表示Python
- 將Python程式(.py)轉換為Windows可執行檔案(.exe)PythonWindows
- vscode如何將所有檔案格式lf批次轉換為crlfVSCode
- 如何將檔案PDF格式轉換成Word格式
- 用Python將word檔案轉換成htmlPythonHTML