0

I use JAXB to convert an XML to a Java class. I have two Java classes: Milestone and Issue. Both have a unique ID and the ID fields are annotated with "@XMLID".

One milestone consists of several issues, so that it has a field variable "issues" holding a List. Issues and Milestones are both contained in parent class, so that Issues are no children of Milestones, but rather siblings. Using schemagen, I generated an XMLSchema to validate the XML file. The schema works well on everything except the "issues"-field of Milestone. Here, I had to manually change this line:

<xs:element name="issue" type="xs:IDREF" minOccurs="0" maxOccurs="unbounded"/>

to be of type IDREFS instead:

<xs:element name="issue" type="xs:IDREFS" minOccurs="0" maxOccurs="unbounded"/>

Now, it works perfectly. My question is: How do I have to annotate my field "issues" in the Milestone class so that I don't have to change the XMLSchema manually afterwards? I tried @XMLIDREFS but this does not seem to be valid.

Here are relevant parts of my code:

XMLSchema of Issue and Milestone

<xs:complexType name="issue">
    <xs:element name="id" type="xs:ID" minOccurs="0"/>
</xs:complexType>
<xs:complexType name="milestone">
    <xs:sequence>
        <xs:element name="id" type="xs:ID" minOccurs="0"/>
        <xs:element name="issue" type="xs:IDREFS" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
 </xs:complexType>

Java class Milestone with current annotation

public class Milestone {
    private String id;
    private List<Issue> issues = new LinkedList<>();

    @XmlElement(name = "issue")
    public List<Issue> getIssues() {
        return issues;
    }

Example XML

<RootElement>
    <issue>
        <id>IssueID1</id>
    </issue>
    <issue>
        <id>IssueID2</id>
    </issue>
    <milestone>
        <id>MilestoneID1</id>
        <issue>IssueID1</issue>
        <issue>IssueID2</issue>
    </milestone>
</parent>
dbc
  • 104,963
  • 20
  • 228
  • 340
fransie
  • 67
  • 8

0 Answers0