XML绑定生成文件无法编译

Cha*_*s S 7 java xml delphi binding xsd

我正在开发一个涉及带有Delphi前端的Java后端的项目.我试图在java中生成基于.xsd的XML绑定.XSD包含一个名为TaskList的对象,其中包含项目Tasks.任务是任务列表.当我生成XML绑定时,Delphi使用TXMLTaskList尝试CreateCollection()函数,但抛出错误,因为TXMLTaskList是IXMLNode而不是IXMLNodeCollection.

我仍然是使用XSD文件和XML绑定生成功能的新手,但基于我所理解的一点点我正在假设,因为TaskList包含单个对象任务,它不应该在CreateCollection函数中使用,而是我会认为应该使用作为任务列表的任务.

这是我的XML绑定文件抛出错误的行:

FExportOnClientChange := CreateCollection(TXMLTaskList, IXMLTask, 
  'exportOnClientChange') as IXMLTaskList;
Run Code Online (Sandbox Code Playgroud)

这是我的TXMLTaskLisk,显示它是TXMLNode而不是TXCnodeCollectionClass,CreateCollection正在寻找.

type
  TXMLTaskList = class(TXMLNode, IXMLTaskList)
  protected
    { IXMLTaskList }
    function Get_Tasks: IXMLTasks;
  public
    procedure AfterConstruction; override;
  end;
Run Code Online (Sandbox Code Playgroud)

在我试图找出问题的时候,我注意到如果我将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>
Run Code Online (Sandbox Code Playgroud)

Rya*_*yan 0

在德尔福部门,你只能靠自己。

话虽如此,我确实使用 xjc 和 xsd 文件来生成 Java 类。

看来您在问题中包含了您知道错误的 xsd 示例。在您的 xsd 示例中,您有一系列序列 - 我希望您的示例生成一个包含任务对象集合的类。

如果我正确理解你的问题,你想要的就是 TaskList 包含任务集合。那应该不会太难。你尝试了什么?

以下是如何生成包含各个 Threshold 对象列表的 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>
Run Code Online (Sandbox Code Playgroud)

这是生成的 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, Named, Visitable, CopyTo, Equals, HashCode, 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;
    ...
Run Code Online (Sandbox Code Playgroud)

我应该将 ThresholdsType 中的“阈值”字段重命名为“阈值”,但除此之外它效果很好。

这不行吗?

<complexType name="TaskList">
   <sequence>
     <element ref="struct:task" maxOccurs="unbounded" minOccurs="0"/>
   </sequence>
</complexType>
Run Code Online (Sandbox Code Playgroud)