users@jaxb.java.net

Re: JAXB/XJC How to change the default namespace?

From: Malachi de Ælfweald <malachid_at_gmail.com>
Date: Tue, 25 Aug 2009 07:32:03 -0700

You control that with your NamespacePrefixMapper...

Assuming you had set 'targetNamespaceURI' to the URI of the one you want to
be default (since only one can be):

        public String getPreferredPrefix(String namespaceURI, String
suggestion, boolean requirePrefix)
        {
                if((targetNamespaceURI != null) && (!requirePrefix) &&
(namespaceURI != null))
                {
                        if(targetNamespaceURI.equals(namespaceURI))
                                *return "";* // this is our targetNamespace
                }
... etc ...


Malachi de Ælfweald
http://www.google.com/profiles/malachid


On Tue, Aug 25, 2009 at 2:21 AM, Florian Bachmann
<f.bachmann_at_micromata.de>wrote:

> 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)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>