可以使用XJC生成類:
xjc -p <your package> <your XSD>
對於您的情況,以下是爲您的XML的XSD:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="PublishRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="Requests">
<xs:complexType>
<xs:sequence>
<xs:element name="Request">
<xs:complexType>
<xs:sequence>
<xs:element name="ChildRequest">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="name"/>
<xs:element type="xs:string" name="id"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:string" name="requestid"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
ObjectFactory類:
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
// 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: 2012.09.25 at 11:57:53 AM GMT+05:30
//
package com.test;
import javax.xml.bind.annotation.XmlRegistry;
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the com.test package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* provided in this class.
*
*/
@XmlRegistry
public class ObjectFactory {
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.test
*
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link PublishRequest }
*
*/
public PublishRequest createPublishRequest() {
return new PublishRequest();
}
/**
* Create an instance of {@link PublishRequest.Requests.Request.ChildRequest }
*
*/
public PublishRequest.Requests.Request.ChildRequest createPublishRequestRequestsRequestChildRequest() {
return new PublishRequest.Requests.Request.ChildRequest();
}
/**
* Create an instance of {@link PublishRequest.Requests.Request }
*
*/
public PublishRequest.Requests.Request createPublishRequestRequestsRequest() {
return new PublishRequest.Requests.Request();
}
/**
* Create an instance of {@link PublishRequest.Requests }
*
*/
public PublishRequest.Requests createPublishRequestRequests() {
return new PublishRequest.Requests();
}
}
PublishRequest類:
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
// 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: 2012.09.25 at 11:57:53 AM GMT+05:30
//
package com.test;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="Requests">
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="Request">
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="ChildRequest">
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="id" type="{http://www.w3.org/2001/XMLSchema}string"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </element>
* </sequence>
* <attribute name="requestid" type="{http://www.w3.org/2001/XMLSchema}string" />
* </restriction>
* </complexContent>
* </complexType>
* </element>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </element>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"requests"
})
@XmlRootElement(name = "PublishRequest")
public class PublishRequest {
@XmlElement(name = "Requests", required = true)
protected PublishRequest.Requests requests;
/**
* Gets the value of the requests property.
*
* @return
* possible object is
* {@link PublishRequest.Requests }
*
*/
public PublishRequest.Requests getRequests() {
return requests;
}
/**
* Sets the value of the requests property.
*
* @param value
* allowed object is
* {@link PublishRequest.Requests }
*
*/
public void setRequests(PublishRequest.Requests value) {
this.requests = value;
}
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="Request">
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="ChildRequest">
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="id" type="{http://www.w3.org/2001/XMLSchema}string"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </element>
* </sequence>
* <attribute name="requestid" type="{http://www.w3.org/2001/XMLSchema}string" />
* </restriction>
* </complexContent>
* </complexType>
* </element>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"request"
})
public static class Requests {
@XmlElement(name = "Request", required = true)
protected PublishRequest.Requests.Request request;
/**
* Gets the value of the request property.
*
* @return
* possible object is
* {@link PublishRequest.Requests.Request }
*
*/
public PublishRequest.Requests.Request getRequest() {
return request;
}
/**
* Sets the value of the request property.
*
* @param value
* allowed object is
* {@link PublishRequest.Requests.Request }
*
*/
public void setRequest(PublishRequest.Requests.Request value) {
this.request = value;
}
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="ChildRequest">
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="id" type="{http://www.w3.org/2001/XMLSchema}string"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </element>
* </sequence>
* <attribute name="requestid" type="{http://www.w3.org/2001/XMLSchema}string" />
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"childRequest"
})
public static class Request {
@XmlElement(name = "ChildRequest", required = true)
protected PublishRequest.Requests.Request.ChildRequest childRequest;
@XmlAttribute
protected String requestid;
/**
* Gets the value of the childRequest property.
*
* @return
* possible object is
* {@link PublishRequest.Requests.Request.ChildRequest }
*
*/
public PublishRequest.Requests.Request.ChildRequest getChildRequest() {
return childRequest;
}
/**
* Sets the value of the childRequest property.
*
* @param value
* allowed object is
* {@link PublishRequest.Requests.Request.ChildRequest }
*
*/
public void setChildRequest(PublishRequest.Requests.Request.ChildRequest value) {
this.childRequest = value;
}
/**
* Gets the value of the requestid property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getRequestid() {
return requestid;
}
/**
* Sets the value of the requestid property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setRequestid(String value) {
this.requestid = value;
}
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="id" type="{http://www.w3.org/2001/XMLSchema}string"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"name",
"id"
})
public static class ChildRequest {
@XmlElement(required = true)
protected String name;
@XmlElement(required = true)
protected String id;
/**
* 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 id property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getId() {
return id;
}
/**
* Sets the value of the id property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setId(String value) {
this.id = value;
}
}
}
}
}
顯示輸出XML,你現在得到的。 – basiljames
它產生 ChildRequest> PublishRequest> 沒有請求標籤 –
任何想法如何解決這個問題!!!! ! –