将Schema文件转换为Java文件
来源:互联网 发布:ipad上传淘宝宝贝软件 编辑:程序博客网 时间:2024/06/01 08:53
可通过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>
- 将Schema文件转换为Java文件
- 将Java文件转换为HTML文件
- 使用SchemaOutputResolver将java文件生成schema
- 将CHM文件转换为HTML文件
- 将WSDL文件转换为C#文件
- 如何将XML转换成XSD(XML Schema)文件
- 将java的jar包转换为dll文件
- 使用JAVA将File文件转换为byte[]数组
- android-将.java文件转换为jar包(八)
- java 将.amr音频文件转换为.mp3或.wav文件
- 如何将java文件夹转换为jar文件
- Java调用MATLAB,将文件转换为二进制流
- JAVA 将xml Schema 文档转化成 XML文件
- Source Insight 将UTF-8格式的JAVA文件转换为GB2312格式的JAVA文件
- Source Insight 将UTF-8格式的JAVA文件转换为GB2312格式的JAVA文件
- 将 Jar 文件转换为 Exe 可执行文件
- 如何将ASPX 转换为静态文件。
- 将xml文件转换为DataSet
- 理解Xen的network-bridge模式
- 正向工程之使用 Rational rose 2003 生成C++代码
- va_list ,va_start,va_end的使用
- Java面向对象【经典案例】参数:尽可能简单的转换
- 如何用Rational Rose进行数据库结构分析
- 将Schema文件转换为Java文件
- R语言多元线性回归
- Java面向对象【经典案例】数组是对象,其变量的值是引用地址
- http和https的区别
- Java面向对象【经典案例】Java 只有一种参数参数传递规则: 基于值的传递!
- SQLserver中把数据文件保存在不同的盘中
- 保准C知识05
- Oracle中bin_to_num()函数的用法
- Java中对象的实例化过程