users@jaxb.java.net

Namespace issues

From: Brian Pontarelli <brian_at_pontarelli.com>
Date: Tue, 08 May 2007 15:35:23 -0600

I'm having some namespace issues and I'm wondering if anyone else has
solved these (more than likely). I can't seem to get my namespaces to
not use the nsX prefixes even using a NamespacePrefixMapper instance (or
whatever the class is). The NamespacePrefixMapper is being asked for
prefixes twice, once with empty string and once with my namespace. My
schema is pretty simple:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
              
xmlns="http://www.inversoft.com/schemas/profanity-1.0/database"
    
targetNamespace="http://www.inversoft.com/schemas/profanity-1.0/database">
  <xs:simpleType name="profanityType">
    <xs:restriction base="xs:NMTOKEN">
      <xs:enumeration value="Alcohol"/>
      <xs:enumeration value="Drug"/>
      <xs:enumeration value="Religion"/>
      <xs:enumeration value="Slang"/>
      <xs:enumeration value="Superlative"/>
      <xs:enumeration value="Swear"/>
      <xs:enumeration value="Youth"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="lang_code">
    <xs:restriction base="xs:string">
      <xs:pattern value="[a-z]{2}"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="country_code">
    <xs:restriction base="xs:string">
      <xs:pattern value="[A-Z]{2}"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:complexType name="entryType">
    <xs:annotation>
      <xs:documentation>
        The body of this element is the description and everything else
is on attributes.
      </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="phrase" type="xs:string" minOccurs="1"
maxOccurs="1"/>
      <xs:element name="alternatives" type="xs:string" minOccurs="1"
maxOccurs="1"/>
      <xs:element name="regex_list" type="xs:string" minOccurs="1"
maxOccurs="1"/>
      <xs:element name="excludes" type="xs:string" minOccurs="1"
maxOccurs="1"/>
      <xs:element name="definition" type="xs:string" minOccurs="1"
maxOccurs="1"/>
      <xs:element name="langauge_code" type="lang_code" minOccurs="1"
maxOccurs="1"/>
      <xs:element name="country_code" type="country_code" minOccurs="1"
maxOccurs="1"/>
      <xs:element name="is_embeddable" type="xs:boolean" minOccurs="1"
maxOccurs="1"/>
      <xs:element name="is_word" type="xs:boolean" minOccurs="1"
maxOccurs="1"/>
      <xs:element name="is_noun" type="xs:boolean" minOccurs="1"
maxOccurs="1"/>
      <xs:element name="is_verb" type="xs:boolean" minOccurs="1"
maxOccurs="1"/>
      <xs:element name="is_adverb" type="xs:boolean" minOccurs="1"
maxOccurs="1"/>
      <xs:element name="is_adjective" type="xs:boolean" minOccurs="1"
maxOccurs="1"/>
      <xs:element name="is_command" type="xs:boolean" minOccurs="1"
maxOccurs="1"/>
      <xs:element name="is_phrase" type="xs:boolean" minOccurs="1"
maxOccurs="1"/>
      <xs:element name="is_exclamation" type="xs:boolean" minOccurs="1"
maxOccurs="1"/>
    </xs:sequence>
  </xs:complexType>
  <xs:element name="entries">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="entry" type="entryType" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>


However, there seems to be something that XJC is generating that has no
namespace and I'm not certain what it is. Even in that instance, I made
my NamespacePrefixMapper look like this and it doesn't help:

public class PrefixMapper extends NamespacePrefixMapper {
    public String getPreferredPrefix(String uri, String suggestion,
boolean required) {
        if (uri.equals("")) {
            return "ns1";
        }

        System.out.println("Handed [" + uri+ "] and [" + suggestion+ "]
and [" + required + "]");
        return "";
    }
}

Any thoughts?

-bp