0

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?

trylimits
  • 2,575
  • 1
  • 22
  • 32
rpfujiw
  • 57
  • 1
  • 10
  • I appreciate the english lesson trylimits but an answer of some sort would be better appreciated – rpfujiw Dec 03 '14 at 22:17

1 Answers1

1

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).

What I also can imagine:

  • @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).
lexicore
  • 42,748
  • 17
  • 132
  • 221