Rectangle 27 0

JAXB in java 6 not prefixing the correct namespace prefix in marshalled XML file?


Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

@pradeep: Nice. Even though you make yourself dependent on a specific implementation it's good to know.

Don't totally agree on the "meaningless" part. It may be "meaningless" from a technical point of view. But assume that e.g. - in any way - a human will see or work with the XML, it might be important to be able to set the namespace prefixes in a meaningful way...

The name of the prefix is meaningless. All it does is make a connection between a namespace and the tags that belong to that namespace. Whether the prefix is abc or namespace01 or there is no prefix because the default namespace is used doesn't matter. As far as I know you can't force the usage of a prefix or the specific name of a prefix in JAXB.

thanks musiKk, now I understand it. But if we want to use our own defined prefix, we can use JAXB RI which contains NamespacePrefixMapper along with JAXB from Java 6. [include JAXB RI in classpath]. marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespaceMapper());

Note
Rectangle 27 0

JAXB in java 6 not prefixing the correct namespace prefix in marshalled XML file?


In the article below I demonstrate how this can be achieved using NamespacePrefixMapper from the JAXB RI, and the @XmlSchema annotation with EclipseLink JAXB (MOXy):

Note
Rectangle 27 0

JAXB in java 6 not prefixing the correct namespace prefix in marshalled XML file?


@pradeep: Nice. Even though you make yourself dependent on a specific implementation it's good to know.

Don't totally agree on the "meaningless" part. It may be "meaningless" from a technical point of view. But assume that e.g. - in any way - a human will see or work with the XML, it might be important to be able to set the namespace prefixes in a meaningful way...

The name of the prefix is meaningless. All it does is make a connection between a namespace and the tags that belong to that namespace. Whether the prefix is abc or namespace01 or there is no prefix because the default namespace is used doesn't matter. As far as I know you can't force the usage of a prefix or the specific name of a prefix in JAXB.

thanks musiKk, now I understand it. But if we want to use our own defined prefix, we can use JAXB RI which contains NamespacePrefixMapper along with JAXB from Java 6. [include JAXB RI in classpath]. marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespaceMapper());

Note
Rectangle 27 0

JAXB in java 6 not prefixing the correct namespace prefix in marshalled XML file?


In the article below I demonstrate how this can be achieved using NamespacePrefixMapper from the JAXB RI, and the @XmlSchema annotation with EclipseLink JAXB (MOXy):

Note