问题
I have a problem while unmarshalling an XML document. I found good hints here ("JAXB- @XmlMixed usage for reading @XmlValue and @XmlElement") but I wasn't able to adopt this on my code.
First.. here is an example of the xml:
<test>
<content type="text">This is a content text</content>
<content type="attributes">
<attributeGroup name="group1">
<attribute name="attr1">value1</attribute>
</attributeGroup>
<attributeGroup name="group2">
<attribute name="attr2">value2</attribute>
<attribute name="attr3">value3</attribute>
</attributeGroup>
</content>
</test>
Within the content block there could be either a text or several attribute groups with attributes (never both!). Sadly this is a given xml structure and I can't change it.
I tried it with the following class structures but there must be an error within my XmlMixed annotation. I even don't know if I must use the @XmlMixed here or if there is another better solution!?
public static class Content {
@XmlMixed
private List<String> text;
@XmlElementRef(name = "attributeGroup", type = AttributeGroup.class)
private List<AttributeGroup> attributeGroups;
// getter+setter...
}
public static class AttributeGroup {
@XmlAttribute(name="name")
private String name;
@XmlElement(name="attribute", type=Attribute.class)
private List<Attribute> attributes;
// getter+setter...
}
public static class Attribute {
@XmlAttribute(name="name")
private String name;
@XmlValue
private String value;
// getter+setter...
}
来源:https://stackoverflow.com/questions/23057726/jaxb-unmarshalling-with-xmlmixed-annotation