Home > Uncategorized > JAXB Undocumented

JAXB Undocumented

When marshalling (Java to XML), how to add multiple namespace declaration in xml.

1. Override  NamespacePrefixMapper
2. Override getPreDeclaredNamespaceUris, getPreferredPrefix methods as per your conveninece.

As of today, I did not find the above tip in any document.

Example
import com.sun.xml.bind.marshaller.NamespacePrefixMapper;

public class PrefixMapperImpl extends NamespacePrefixMapper {

@Override
public String[] getPreDeclaredNamespaceUris() {
String[] result = super.getPreDeclaredNamespaceUris();
result = new String[] { “http://www.w3.org/2001/XMLSchema-instance” };
return result;
}

@Override
public String getPreferredPrefix(String namespaceUri, String suggestion,
boolean requirePrefix) {
String prefix = “xsi”;
if (“urn:something.request”
.equals(namespaceUri))
prefix = “prefix”;
return prefix;
}

}

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: