users@jaxb.java.net

JAXB/XJC How to change the default namespace?

From: Florian Bachmann <f.bachmann_at_micromata.de>
Date: Tue, 25 Aug 2009 11:21:41 +0200

Hello,
I hope you can help me (again).

How do I change the default namespace?

With only one schema file, all works as expected. I create Java
classes from a given schema file. The resulting xml is in the default
namespace.





All works fine and I get the desired default namespace:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2” xmlns:atom="http://www.w3.org/2005/Atom
" xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0" >
<Placemark>



But when I create my classes from Google’s GX extension schema, JAXB
assumes (correct), that the GX extension namespace is the default
namespace (The GX extension schema defines an import of OGC’s KML
schema).




The resulting default namespace (red box in the image):
<kml:kml xmlns="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2
" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0
">
<kml:Placemark>…


But I like OGC’s KML namespace to be the default namespace. The
desired default namespace (green box in the image):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom
" xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0" xmlns:gx="http://www.google.com/kml/ext/2.2
">
<Placemark>…

So how am I able to change the default namespace?
regards Flori

P.S. I set an own "com.sun.xml.bind.namespacePrefixMapper" so the
namespaces have beautiful names (atom, gx, xal, kml, instead of ns1,
ns2, ns3, and ns4)


defaultnamespace_oneschema.png
(image/png attachment: defaultnamespace_oneschema.png)

defaultnamespace_twoschemas.png
(image/png attachment: defaultnamespace_twoschemas.png)