users@jaxb.java.net

RE: RE: RE: Default Namespace in JAXB

From: Malachi de AElfweald <malachi_at_eoti.org>
Date: Wed, 28 Jul 2004 19:10:59 -0700

This is what I am doing:

package org.eoti.spec;

import com.sun.xml.bind.marshaller.NamespacePrefixMapper;
import java.util.*;

public class NSPrefixMapper
extends NamespacePrefixMapper
{
         HashMap mappings;

         public NSPrefixMapper()
         {
                 mappings = new HashMap();
                 setDefaultMappings();
         }

         protected void setDefaultMappings()
         {
                 clear();
                 addMapping("http://devel.eoti.org/pandora", "pandora");
                 addMapping("http://www.w3.org/2001/XMLSchema-instance",
"xsi");
                 addMapping("http://java.sun.com/xml/ns/jaxb", "jaxb");
         }

         public void addMapping(String uri, String
prefix){mappings.put(uri, prefix);}
         public String getMapping(String uri){return
(String)mappings.get(uri);}
         public HashMap getMappings(){return mappings;}
         public void clear(){mappings.clear();}

         public String getPreferredPrefix(String namespaceURI, String
suggestion, boolean requirePrefix)
         {
                 String toReturn = getMapping(namespaceURI);
                 if(toReturn != null)
                         return toReturn;

                 return suggestion;
         }
}


At 06:06 AM 7/28/2004, you wrote:
>I believe that the default ns1 will be put on namespace if this method
>returns blank (so your code is working). Maybe someone else can tell you
>how to get around that. Personally I would keep the ebagent namespace if
>that is what it belongs to.
>
>Thank you
>
>Ted D. Poovey
>Software Engineer III
>U.S. Central
>Phone : (913) 227-6106
>Fax : (913) 227-6254
>
>-----Original Message-----
>From: Vishal.Manchanda_at_iflexsolutions.com
>[mailto:Vishal.Manchanda_at_iflexsolutions.com]
>Sent: Tuesday, July 27, 2004 11:10 PM
>To: users_at_jaxb.dev.java.net
>Cc: users_at_jaxb.dev.java.net
>Subject: RE: RE: Default Namespace in JAXB
>
>
>
>I’ve already created NamespacePrefixMapperImpl and the property was set
>for the marshaller
>
>But my concern is
>
>public String getPreferredPrefix(String namespaceUri, String suggestion,
>boolean requirePrefix) {
> // I want this namespace to be mapped to "xsi"
> if(
> "http://www.w3.org/2001/XMLSchema-instance".equals(namespaceUri) )
> return "xsi";
> // I want this namespace to be mapped to "" i.e I want ebagent as
> default namespace.
> if( "ebagent".equals(namespaceUri) )
> return "";
>
> // otherwise I don't care. Just use the default suggestion,
> whatever it may be.
> return suggestion;
> }
>
>In the abocve method ,in case of ebagent , the prefix returned after
>marshalling is “ns1” whereas I want it to return “”.
>
>Please suggest.
>
>In the output I want like this
>
><msg xmlns=”ebagent” >
>………………
>……………
>.
></msg>
>
>
>
>----------
>From: Ted Poovey [mailto:tpoovey_at_uscentral.coop]
>Sent: Tuesday, July 27, 2004 6:37 PM
>To: users_at_jaxb.dev.java.net
>Subject: RE: Default Namespace in JAXB
>
>Create you own and use it. Class is NamespacePrefixMapperImpl and
> marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper",
> new NamespacePrefixMapperImpl());
>
>Thank you
>
>Ted D. Poovey
>Software Engineer III
>U.S. Central
>Phone : (913) 227-6106
>Fax : (913) 227-6254
>
>-----Original Message-----
>From: Vishal.Manchanda_at_iflexsolutions.com
>[mailto:Vishal.Manchanda_at_iflexsolutions.com]
>Sent: Tuesday, July 27, 2004 1:43 AM
>To: users_at_jaxb.dev.java.net
>Subject: Default Namespace in JAXB
>
>
>Hi,
>I’m using JAXB.
>In my xml I need default namespace to be shown after marshalling.
>Like this
>
><msg xmlns=”dnamespace” >
>………………
>……………
>.
></msg>
>
>
>I’m using my own NamespacePrefixMapperImpl
>But it is automatically generating “ns1” as prefix whereas I do not want
>any prefix
>It is showing output as
>
><msg xmlns:ns1=”dnamespace” >
>………………
>……………
>.
></msg>
>
>Please suggest how I can declare default namespaces using JAXB
>
>
>
>Vishal Manchanda
> Associate Consultant , e-Solutions
> PrimeSourcing™,“ Add Value Reduce Risk” The Global IT Services
> business from i-flex
> i-flex Solutions Ltd-Mumbai
> Tel: 91-22-5668 5362 OR 91-22-28391909 xtn-5360
> Cell: 91-98925 20922
>
><www.iflexsolutions.com/services/services.htm>www.iflexsolutions.com/services/services.asp
> Email: vishal.manchanda_at_iflexsolutions.com
>
>