JAXB自定义命名空间前缀问题 [英] JAXB custom namespace prefix issue

查看:165
本文介绍了JAXB自定义命名空间前缀问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何其他方法可以使用除包级别注释 @Xmlns 之外的注释来控制自定义名称空间前缀。

Is there any other way to control the custom namespace prefixes using annotations other than in the package level annotation @Xmlns.

可以在元素级别完成吗?
也可以有一个带有多个前缀的命名空间?

Can it be done at the element level? Also is it possible to have one namespace with multiple prefixes?

推荐答案

实际上你想做什么?为什么名称空间前缀对您很重要?

What do you want to do, actually? Why are namespace prefixes important for you?

名称空间前缀没有标准的元素级注释。

There are no standard element-level annotations for namespace prefixes.

我知道控制名称空间前缀的选项是:

The options to control namespace prefixes I know are:

  • @XmlNS you already mentioned.
  • Providing a custom NamespacePrefixMapper.
  • Lower-level handling of XML (for instance, on the StAX, SAX or DOM level).

我还能想象:


  • @XmlElementRef / @XmlElementRefs 通常使用具有带前缀的QNames的JAXBElements。也许会使用这个前缀。

  • 您可以拥有 QName -typed属性( xs:QName 在XSD中),它也可用于添加命名空间映射。

  • 可能是 @XmlAnyElement (包含DOM元素)。

  • 我想我也看到了 XmlAdapter 的方向 - 我觉得某处有一个选项因为它是 NamespacePrefixMapper -aware。 (实际上需要名称空间感知类型,如 QName )。

  • @XmlElementRef/@XmlElementRefs normally use JAXBElements which have QNames which have prefixes. Maybe this prefix will be used.
  • You can have a QName-typed property (xs:QName in XSD), it also may be used to add a namespace mapping.
  • Probably something in direction of @XmlAnyElement (containing DOM element).
  • I think I also saw something in direction of XmlAdapter - I think there was an option somewhere for it to be NamespacePrefixMapper-aware. (Actually needed for namespace-aware types like QName).

这篇关于JAXB自定义命名空间前缀问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆