0
私はJAXBを初めて使用しています。 XSDファイルを右クリックしてEclipseの機能を組み込んだXSDファイルからJAXBクラスを作成しました。XSDファイルは、JAXBを使用してネストされた静的クラスを作成します。
しかし、結局のところ、入れ子になった静的な内部クラスを持つクラスです。
ここに問題があります:私はマーシャリングとXMLファイルを作成しようとしています。しかし、どうやって入れ子の内部クラスを外部クラスと一緒に渡すのですか?
public class OuterClass {
String x = "None of the methods or variables are static in the inner our outer class";
public static class InnerClass{
}
}
XMLは:終了タグもあり、この
<OuterClass RequestType="LogOn" ApplicationSender="Example"
WorkstationID="001">
<InnerClass>
<TimeStamp>2 009-11-20T17:30:50</TimeStamp>
<InterfaceVersion>01.00</InterfaceVersion>
</InnerClass>
ようになっているはずですが、プレビューで、何らかの理由でそれが現れていません。ここでは、作成したクラスだ
<?xml version="1.0" encoding="utf-8"?>
<!--IFSF POS-FDC Schema 23 November 2010-->
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.02" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="FDC_Basic_Types.xsd"/>
<xs:include schemaLocation="FDC_DR_CurrencyCode_Full.xsd"/>
<xs:element name="ServiceRequest">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="POSdata">
<xs:complexType>
<xs:sequence>
<xs:element name="POSTimeStamp" type="specialtime"/>
<xs:element name="InterfaceVersion" type="InterfaceVersion"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="RequestType" type="RequestType" fixed="LogOn" use="required" />
<xs:attribute name="ApplicationSender" type="ApplicationSender" use="required" />
<xs:attribute name="WorkstationID" type="WorkstationID" use="required" />
<xs:attribute name="RequestID" type="RequestID" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>
:
は、ここで実際のXSDファイルです
<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="POSdata">
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="POSTimeStamp" type="{}specialtime"/>
* <element name="InterfaceVersion" type="{}InterfaceVersion"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </element>
* </sequence>
* <attribute name="RequestType" use="required" type="{}RequestType" fixed="LogOn" />
* <attribute name="ApplicationSender" use="required" type="{}ApplicationSender" />
* <attribute name="WorkstationID" use="required" type="{}WorkstationID" />
* <attribute name="RequestID" use="required" type="{}RequestID" />
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"content"
})
@XmlRootElement(name = "ServiceRequest")
public class ServiceRequest {
@XmlElementRef(name = "POSdata", type = JAXBElement.class)
@XmlMixed
protected List<Serializable> content;
@XmlAttribute(name = "RequestType", required = true)
protected RequestType requestType;
@XmlAttribute(name = "ApplicationSender", required = true)
protected String applicationSender;
@XmlAttribute(name = "WorkstationID", required = true)
protected String workstationID;
@XmlAttribute(name = "RequestID", required = true)
protected String requestID;
/**
* Gets the value of the content 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 content property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getContent().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link JAXBElement }{@code <}{@link ServiceRequest.POSdata }{@code >}
* {@link String }
*
*
*/
public List<Serializable> getContent() {
if (content == null) {
content = new ArrayList<Serializable>();
}
return this.content;
}
/**
* Gets the value of the requestType property.
*
* @return
* possible object is
* {@link RequestType }
*
*/
public RequestType getRequestType() {
if (requestType == null) {
return RequestType.LOG_ON;
} else {
return requestType;
}
}
/**
* Sets the value of the requestType property.
*
* @param value
* allowed object is
* {@link RequestType }
*
*/
public void setRequestType(RequestType value) {
this.requestType = value;
}
/**
* Gets the value of the applicationSender property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getApplicationSender() {
return applicationSender;
}
/**
* Sets the value of the applicationSender property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setApplicationSender(String value) {
this.applicationSender = value;
}
/**
* Gets the value of the workstationID property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getWorkstationID() {
return workstationID;
}
/**
* Sets the value of the workstationID property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setWorkstationID(String value) {
this.workstationID = 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="POSTimeStamp" type="{}specialtime"/>
* <element name="InterfaceVersion" type="{}InterfaceVersion"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"posTimeStamp",
"interfaceVersion"
})
public static class POSdata {
@XmlElement(name = "POSTimeStamp", required = true)
protected String posTimeStamp;
@XmlElement(name = "InterfaceVersion", required = true)
protected String interfaceVersion;
/**
* Gets the value of the posTimeStamp property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getPOSTimeStamp() {
return posTimeStamp;
}
/**
* Sets the value of the posTimeStamp property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setPOSTimeStamp(String value) {
this.posTimeStamp = value;
}
/**
* Gets the value of the interfaceVersion property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getInterfaceVersion() {
return interfaceVersion;
}
/**
* Sets the value of the interfaceVersion property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setInterfaceVersion(String value) {
this.interfaceVersion = value;
}
}
}
私はそれを行うことがしたいです。しかし、内部クラスを設定する外部クラスにはメソッドがありません。また、私は自動生成されたクラスを編集したくありません。 – Saurin
実際のコードとそのコードを生成するために使用された実際のxsdを貼り付けてください。 –
元の投稿を編集してコードを追加しました。ありがとう – Saurin