users@jaxb.java.net

NamespacePrefixMapper

From: Roland Prähofer <rp_at_memeticdesign.de>
Date: Sat, 14 Nov 2009 17:20:03 +0100

Hello!

I have a document with multiple schemas, it's a foxml document for the
fedora commons document server.

I've created JAXBinding classes with xjc for the foxml schema and
added some classes for elements in a different namespaces.
They're all in the same package.

I'd like to marshall a document assembled in my application,
so that the prefixes are as desired.


I tried to add all the namespace/prefix mappings in the package-info.class:

@javax.xml.bind.annotation.XmlSchema(
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
xmlns = {
     @javax.xml.bind.annotation.XmlNs(prefix = "foxml",
     namespaceURI = "info:fedora/fedora-system:def/foxml#"),
     @javax.xml.bind.annotation.XmlNs(prefix = "oai_dc",
     namespaceURI = "http://www.openarchives.org/OAI/2.0/oai_dc/"),
     @javax.xml.bind.annotation.XmlNs(prefix = "dc",
     namespaceURI = "http://purl.org/dc/elements/1.1/"),
     ...

That didn't work...

Then I was trying to use my own NamespacePrefixMapper and tell the
marshaller about it:

m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new
FedoraNamespacePrefixMapper());

Didn't work either, I got

Exception in thread "main" javax.xml.bind.PropertyException:
         at
javax.xml.bind.helpers.AbstractMarshallerImpl.getProperty(AbstractMarshallerImpl.java:367)
         at
com.sun.xml.bind.v2.runtime.MarshallerImpl.getProperty(MarshallerImpl.java:494)
         at tester.Main.main(Main.java:70)



Any ideas?!

Regards, Roland