JAXB 解组 X,X*

JAXB Unmarshalling X,X*

我在从 XML 解组此 class 时遇到问题。

问题是由名为 'propertyset' 的两个元素引起的。实际发生的是第一个属性集被正确解组然后立即被第二个属性集覆盖,如果它存在的话...

有什么 annotation/configuration 可以用来成功解组这个 XML 吗?

/**
 * <p>Java class for a element declaration.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * <element name="a">
 *   <complexType>
 *     <complexContent>
 *       <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *         <sequence>
 *           <element ref="propertyset"/>
 *           <element ref="propertyset" minOccurs="0"/>
 *         </sequence>
 *         <attribute name="id" type="{http://www.w3.org/2001/XMLSchema}long" />
 *         <attribute name="description" type="{http://www.w3.org/2001/XMLSchema}string" />
 *       </restriction>
 *     </complexContent>
 *   </complexType>
 * </element>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "propertyset",
    "systempropertyset"
}, factoryMethod = "createAEx", factoryClass = ObjectFactoryEx.class)
@XmlRootElement(name = "a")
public class A
{
    @XmlElement(required = true, type = B.class)
    protected B propertyset;
    @XmlElement(name = "propertyset", type = B.class)
    protected B systempropertyset;
...
}

我现在开始使用 Moxy。有了这个我可以使用@XmlPath("propertyset[1]") 和@XmlPath("propertyset[2]")

这与宣传的一样有效!