我有以下 XML。
<elementAttributes>
<elementAttribute>
<attributeName>BIFM Service</attributeName>
<attributeValues>
<attributeValue>AssetCollector</attributeValue>
</attributeValues>
</elementAttribute>
<elementAttribute>
<attributeName>Search Service</attributeName>
<attributeValues>
<attributeValue>BudgetEstimator</attributeValue>
</attributeValues>
</elementAttribute>
<elementAttribute>
<attributeName>AgendizeExternal Service</attributeName>
<attributeValues>
<attributeValue>agendizeExternal</attributeValue>
</attributeValues>
</elementAttribute>
</elementAttributes>
现在 JAXB 类应该具有哪些属性/字段?
最佳答案
试试这个
public class Test {
static class Element {
@XmlElement
String attributeName;
@XmlElement
@XmlElementWrapper(name="attributeValues")
List<String> attributeValue;
}
@XmlElement
List<Element> elementAttribute;
public static void main(String[] args) throws Exception {
Test t = JAXB.unmarshal(new File("1.xml"), Test.class);
}
}
关于java - XML 到 JAXB 的绑定(bind)是否具有嵌套元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27717404/