我在JAXB目前从.xsd文件生成java对象的方式上遇到了一些麻烦。下面是我正在使用的.xsd文件的代码片段。这段代码的目的是,它将有一个包含各种信息的对象LogicalDevices列表。
<xs:element name="LogicalDeviceList">
<xs:annotation>
<xs:documentation>List of all LogicalDevices currently added for the application</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="LogicalDevice" minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>An added logical device</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="DeviceDefinitionId" use="required">
<xs:annotation>
<xs:documentation>The DeviceDefinitionId of the Logical device</xs:documentation>
.......... Other LogicalDevice Information
目前JAXB解析器创建一个对象,其中LogicalDeviceList不是LogicalDevices的列表,而LogicDevice返回devicedefinitionid的列表。
由于我接收和解组的XML无论如何都不能更改,是否有办法解决这个问题?是否像将.xsd文件更改为这样的
那样简单?更新:下面的修改不起作用。5-24-2013
<xs:element name="LogicalDeviceList" minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>List of all LogicalDevices currently added for the application</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="LogicalDevice">
<xs:annotation>
<xs:documentation>An added logical device</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="DeviceDefinitionId" use="required">
<xs:annotation>
<xs:documentation>The DeviceDefinitionId of the Logical device</xs:documentation>
如果是这样,为什么c# .xsd解析器按照预期从原始xsd生成对象和列表,而JAXB却没有。
对于XML模式片段:
<xs:element name="LogicalDeviceList">
<xs:annotation>
<xs:documentation>List of all LogicalDevices currently added for the application</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="LogicalDevice" minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>An added logical device</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="DeviceDefinitionId" use="required">
<xs:annotation>
<xs:documentation>The DeviceDefinitionId of the Logical device</xs:documentation>
...
您将获得如下所示的类结构,其中LogicalDeviceList
类具有LogicalDevice
实例的集合。
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"logicalDevice"
})
public static class LogicalDeviceList {
@XmlElement(name = "LogicalDevice")
protected List<LogicalDeviceList.LogicalDevice> logicalDevice;
JAXB可能不完全匹配c#生成的内容,但它是XML模式的完全可接受的表示。