我正在开发一个涉及带有Delphi前端的
Java后端的项目.我试图在java中生成基于.xsd的XML绑定. XSD包含一个名为TaskList的对象,其中包含项目Tasks.任务是任务列表.当我生成XML绑定时,Delphi使用TXMLTaskList尝试CreateCollection()函数,但抛出错误,因为TXMLTaskList是IXMLNode而不是IXMLNodeCollection.
我仍然是使用XSD文件和XML绑定生成功能的新手,但基于我所理解的一点点我正在假设,因为TaskList包含单个对象任务,它不应该在CreateCollection函数中使用,而是我会认为应该使用作为任务列表的任务.
- FExportOnClientChange := CreateCollection(TXMLTaskList,IXMLTask,'exportOnClientChange') as IXMLTaskList;
这是我的TXMLTaskLisk,显示它是TXMLNode而不是TXCnodeCollectionClass,CreateCollection正在寻找.
- type
- TXMLTaskList = class(TXMLNode,IXMLTaskList)
- protected
- { IXMLTaskList }
- function Get_Tasks: IXMLTasks;
- public
- procedure AfterConstruction; override;
- end;
在我试图找出问题的时候,我注意到如果我将TaskList作为一个无限的任务列表并将任务留作任务的无限列表,那么在delphi xml文件中一切都很好,但这意味着我有一个列表一个不是我想要的清单.
这里可能很难说的一点是,TaskList和任务在不同的XSD文件中,尽管它们是链接的.
- <complexType name="TaskList">
- <sequence>
- <element name="tasks" type="struct:tasks"></element>
- </sequence>
- </complexType>
- <complexType name="tasks">
- <sequence>
- <element ref="struct:task" maxOccurs="unbounded" minOccurs="0"></element>
- </sequence>
- </complexType>
解决方法
您在德尔福部门独立.
看起来您在问题中包含了一些您知道错误的xsd示例.在xsd示例中,您有一系列序列 – 我希望您的示例生成一个包含任务对象集合的类.
如果我正确理解你的问题,你想要的是TaskList包含一系列任务.这应该不会太难.你尝试过什么?
以下是我如何生成包含单个阈值对象列表的Thresholds对象的示例:
- <xsd:element name="Thresholds" type="ThresholdsType"/>
- <xsd:complexType name ="ThresholdsType">
- <xsd:sequence>
- <xsd:element ref="Threshold" maxOccurs="unbounded" minOccurs="0"/>
- </xsd:sequence>
- <xsd:attribute name="interpolate" type="xsd:string" use="optional" />
- <xsd:attribute name="parameter" type="xsd:string" use="optional" />
- <xsd:attribute name="unitSystem" type="xsd:string" use="optional" />
- </xsd:complexType>
- <xsd:element name="Threshold" type="ThresholdType"/>
- <xsd:complexType name="ThresholdType">
- <xsd:simpleContent>
- <xsd:extension base="xsd:string">
- <xsd:attribute type="xsd:string" name="id" use="optional"/>
- <xsd:attribute type="xsd:double" name="minInclusive" use="optional"/>
- <xsd:attribute type="xsd:double" name="maxExclusive" use="optional"/>
- </xsd:extension>
- </xsd:simpleContent>
- </xsd:complexType>
以下是生成的ThresholdsType java类的开头:
- @XmlAccessorType(XmlAccessType.FIELD)
- @XmlType(name = "ThresholdsType",propOrder = {
- "threshold"
- })
- @javax.xml.bind.annotation.XmlRootElement(name="ThresholdsType implements Cloneable,Named,Visitable,CopyTo,Equals,HashCode,ToString")
- public class ThresholdsType implements Cloneable,ToString
- {
- @XmlElement(name = "Threshold")
- protected List<ThresholdType> threshold;
- @XmlAttribute(name = "interpolate")
- protected String interpolate;
- @XmlAttribute(name = "parameter")
- protected String parameter;
- @XmlAttribute(name = "unitSystem")
- protected String unitSystem;
- @XmlTransient
- private QName jaxbElementName;
- ...
我应该将ThresholdsType中的“阈值”字段重命名为“阈值”,但除此之外它工作得很好.
这不起作用吗?
- <complexType name="TaskList">
- <sequence>
- <element ref="struct:task" maxOccurs="unbounded" minOccurs="0"/>
- </sequence>
- </complexType>