【发布时间】:2011-07-20 23:23:46
【问题描述】:
我正在为一些 JAXB 解析而苦苦挣扎,需要一些指导。
基本上,我正在尝试将属性添加到我已经使用@XmlElement 声明为元素的类变量中。到目前为止,任何使用 @XmlAttribute 的尝试都会在类级别设置属性。
我目前得到的是:
<DataClass newAttribute="test">
<myElement>I wish this element had an attribute</myElement>
<anotherElement>I wish this element had an attribute too</anotherElement>
</DataClass>
我想这样做:
<DataClass>
<myElement thisAtt="this is what I'm talking about">This is better</myElement>
<anotherElement thisAtt="a different attribute here">So is this</anotherElement>
</DataClass>
我看到其他帖子使用@XmlValue 将属性添加到单个元素,但是当您有元素时这不起作用,并且不适用于多个元素。
有没有人想过如何做到这一点?
谢谢! 杰森
【问题讨论】:
-
您需要发布相关的 Java 代码,以便我们了解实际情况。