Configure namespace prefix in JAXB bindings file
Asked Answered
S

1

7

I generate Java files from an XSD using namespaces. When the corresponding Java objects are serialized to XML the namespaces prefixes are ns1, ns2 ... There seems to be three ways to control the prefixes:

  1. If using Oracle's Java one can add an implementation of the internal class com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper to the marshaller.
  2. If the file package-info.java is under your control then you can add the annotation javax.xml.bind.annotation.XmlNs to it. This does not work when the Java files are generated from a XSD.
  3. You can add a third party tool and configure the javax.xml.bind.annotation.XmlNs annotation in the JAXB binding file.

The 3rd option is non standard and its last version is from 2012. Is there an equivalent standard option available in the meantime, e.g. an element or attribute in the standard namespaces http://java.sun.com/xml/ns/jaxb or http://java.sun.com/xml/ns/jaxb/xjc?

Sepulveda answered 4/5, 2016 at 9:51 Comment(1)
Please see: #4041182Sisera
E
-3

There are newest version of 3rd option Maven Central

Ewers answered 4/5, 2016 at 11:9 Comment(2)
Thank you for the information. This option still relies on Maven. However, I'm looking for an element or attribute in the standard namespaces http://java.sun.com/xml/ns/jaxb or http://java.sun.com/xml/ns/jaxb/xjc. Moreover the Maven plugin still depends on the extension org.jvnet.jaxb2_commons.jaxb2-namespace-prefix which is from 2012.Sepulveda
the serialized xml already has namespaces. It is the namespace prefix I want to configure.Sepulveda

© 2022 - 2024 — McMap. All rights reserved.