Saying my xml should look like the following:
<!-- even I move <A id="2">...</A> here, still has this error-->
<A id="1">
...
... (many levels of nested element)
<C>
<B ref="2"/>
</C>
...
</A>
<A id="2">...</A>
So I define the following xsd file:
<xs:complexType name="A" abstract="true">
<xs:attribute name="id" type="xs:ID" use="required"/>
...
</xs:complexType>
<xs:complexType name="B">
<xs:attribute name="ref" type="xs:IDREF" use="required"/>
</xs:complexType>
But When I want to parse this xml file using JAXB, It always complains that <B ref="2"/>
has a error of:
Undefined ID "".
My code:
public class A {
private String id;
@XmlAttribute
@XmlID
public String getId() {
return id;
}
...
}
public class C {
private A b;
@XmlIDREF
@XmlElement
public A getB() {
return b;
}
}
So what's the problem?
I have already read this blog, this blog, question, not found any clue of this error.