- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我已经看过一些与此相关的讨论,但无法在以下场景中应用。我正在尝试使用 jaxb 解码 xml
。以下是我所有类(class)的层次结构。
@XmlRootElement(name="entry")
class Entry extedns Base{
@XmlElement
private String id;
@XmlElement
private String name;
@XmlElementRef
@XmlMixed
private Begin begin;
@XmlElementRef
@XmlMixed
private End end;
@XmlElementRef
private List<Link> links;
//Getter setters
}
@XmlRootElement(name="begin",namespace = "something")
public class Begin extends AnotherBase{
@XmlValue
private Float mFloat;
//Getter Setters
}
@XmlRootElement(name="end",namespace = "something")
public class End extends AnotherBase{
@XmlValue
private Float mFloat;
//Getter Setters
}
@XmlRootElement(name="link",namespace = "something")
public class Link extends Base{
private String attname;
private String attValue;
//Getter Setters
}
我想要一个像下面这样的 xml:
<entry>
<id>...</id>
<name>...</name>
<begin>1.23344</begin>
<end>5.0</end>
<link>
<link>......</link>
<link>......</link>
</link>
</entry>
尽你所能,
Entry 类有 2 个 @XmlElement
注释变量和 2 个 @XmlElementRef
注释变量 (Begin,End)。
Begin 和 End 类都有 @Xmlvalue
注释变量。
Begin 和 End 类都派生自其他类
Link 类可能具有类型属性和元素的变量。
我未能使用 @XmlMixed
,如您所见,我将 @XmlMixed
放在了 Entry 类中变量声明的顶部。
这次编码的结果是
@XmlValue is not allowed on a class that derives another class.
this problem is related to the following location:
at private java.lang.Float Begin.mFloat
at Begin
at private Begin Entry.begin
If a class has @XmlElement property, it cannot have @XmlValue property.
this problem is related to the following location:
at private java.lang.Float Begin.mFloat
at Begin
最佳答案
您可以使用 @XmlTransient
注释 AnotherBase
以将其作为映射父类(super class)删除。如果 AnotherBase
上有任何未使用 @XmlAttribute
映射的 get/set 方法对,则您需要使用 @XmlTransient
对它们进行注释。
您不需要在 begin
和 end
属性上使用 @XmlMixed
注释。
我注意到您正在注释字段(实例变量)。执行此操作时,应在类 @XmlAccessorType(XmlAccessType.FIELD) 上指定以下内容`
关于java - 如何一起使用 @XmlMixed 、 @XmlElement 和 @XmlValue ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20042592/
我正在尝试创建一个 @XmlAdapter 以将混合列表中的单词拆分为名为 Word 的 Wrapper 类的对象。该字段还可能包含名为 Group 的 Word 扩展的实例。 这个想法是这样的: S
我看到这里发布了一个类似的问题,但它并没有帮助我解决问题,所以我在这里发布我的问题,看看是否有人可以修改我的代码以使其工作。 问题:如何访问混合内容字符串值并将其保存在 setPhrase(Strin
我已经看过一些与此相关的讨论,但无法在以下场景中应用。我正在尝试使用 jaxb 解码 xml。以下是我所有类(class)的层次结构。 @XmlRootElement(name="entry")
我是一名优秀的程序员,十分优秀!