使用xjc将xml文件转换成javabean

 1.先将xml文件转换xsd文件

原xml文件:Response.xml



0
abcd

xsd文件:Response.xsd



 
   
     
       
       
     

   

 

 
 


2.先指定一个目录存放该***.java    例:  D:\trang

cmd进入到该目录

xjc  Response.xsd   -p   Response.bean

使用xjc将xml文件转换成javabean_第1张图片

生成的JavaBean如下:Response.java

//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2017.06.07 at 08:05:42 PM CST
//


package Response.bean;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;


/**
 *

Java class for anonymous complex type.
 *
 *

The following schema fragment specifies the expected content contained within this class.
 *
 *


 * <complexType>
 *   <complexContent>
 *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       <sequence>
 *         <element ref="{}code"/>
 *         <element ref="{}message"/>
 *       </sequence>
 *     </restriction>
 *   </complexContent>
 * </complexType>
 *

 *
 *
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "code",
    "message"
})
@XmlRootElement(name = "Response")
public classResponse {

    @XmlElement(required = true)
    protected String code;
    @XmlElement(required = true)
    protected String message;

    /**
     * Gets the value of the code property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getCode() {
        return code;
    }

    /**
     * Sets the value of the code property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setCode(String value) {
        this.code = value;
    }

    /**
     * Gets the value of the message property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getMessage() {
        return message;
    }

    /**
     * Sets the value of the message property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setMessage(String value) {
        this.message = value;
    }

}


3.将所有的xsd文件转换成javabean

xjc *.xsd -p  com.xyz..bean      (com.xyz..bean)为包名。



你可能感兴趣的:(使用xjc将xml文件转换成javabean)