【问题标题】:Create Element with atom as prefix using JAXB annotations使用 JAXB 注释创建以 atom 作为前缀的元素
【发布时间】:2012-05-07 23:14:12
【问题描述】:

我正在尝试创建一个我想要作为原子前缀的 xml 元素。 我知道我不能这样做:

@XmlElement(prefix="atom")

然后创建

<XmlAttribute>
   <atom:link ...>
</XmlAttribute>

有没有办法做到这一点?

【问题讨论】:

    标签: java annotations jaxb


    【解决方案1】:

    是的,你只需要定义这个前缀对应的命名空间:

    @XmlElement(name="link", namespace="..")
    

    这只会将与 atom 前缀对应的命名空间添加到您的 link 元素中。如果您的问题是关于专门将 atom 作为此命名空间的前缀,请查看以下问题:Is it possible to customize the namespace prefix that JAXB uses when marshalling to a String?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-21
      • 2010-10-03
      • 1970-01-01
      • 2011-05-17
      • 1970-01-01
      相关资源
      最近更新 更多