rpfujiw
rpfujiw

Reputation: 57

JAXB custom namespace prefix issue

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?

Upvotes: 0

Views: 666

Answers (1)

lexicore
lexicore

Reputation: 43651

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

Upvotes: 1

Related Questions