Java – XML binding generation file cannot be compiled

I am developing a project involving Java backend with Delphi front end I tried to generate a Java - based XML binding for XSD The XSD contains an object called tasklist, which contains the project tasks A task is a task list When I generate an XML binding, Delphi uses txmltasklist to try the createcollection() function, but throws an error because txmltasklist is ixmlnode instead of ixmlnodecollection

I am still a novice to use the XSD file and XML binding generation function, but based on my understanding, I am assuming that because the tasklist contains a single object task, it should not be used in the createcollection function, but I think it should be used as a task list

This is the line where my XML binding file threw an error:

FExportOnClientChange := CreateCollection(TXMLTaskList,IXMLTask,'exportOnClientChange') as IXMLTaskList;

This is my txmltasklisk. It shows that it is txmlnode instead of txcnodecollectionclass. Createcollection is looking for it

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

When I tried to find out the problem, I noticed that if I took the tasklist as an infinite task list and left the task as an infinite task list, everything would be fine in the Delphi XML file, but this means that I have a list, a list that is not what I want

It may be difficult to say here that tasklist and task are in different XSD files, although they are linked

<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>

Solution

You are independent in Delphi department

Having said that, I do use xjc and XSD files to generate Java classes

It seems that you have included some XSD examples in the problem that you know are wrong In the XSD example, you have a sequence – I want your example to generate a class that contains a collection of task objects

If I understand your question correctly, what you want is that the task list contains a series of tasks It shouldn't be too difficult What have you tried?

The following is an example of how I generated a thresholds object that contains a list of individual threshold objects:

<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>

The following is the beginning of the generated thresholdstype Java class:

@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;
    ...

I should rename the threshold field in thresholdstype to threshold, but it works well beyond that

Doesn't it work?

<complexType name="TaskList">
   <sequence>
     <element ref="struct:task" maxOccurs="unbounded" minOccurs="0"/>
   </sequence>
</complexType>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>