6

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?

Community
  • 1
  • 1
Claude
  • 1,724
  • 3
  • 17
  • 46
  • 1
    Please see: https://stackoverflow.com/questions/4040682/jaxb-in-java-6-not-prefixing-the-correct-namespace-prefix-in-marshalled-xml-file/4041337 – lexicore May 27 '20 at 11:28

1 Answers1

-3

There are newest version of 3rd option Maven Central

Andrei_N
  • 437
  • 2
  • 15
  • 1
    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. – Claude May 04 '16 at 11:44
  • 3
    the serialized xml already has namespaces. It is the namespace **prefix** I want to configure. – Claude May 04 '16 at 12:23