users@jaxb.java.net

Re: Namespace issues

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

I figured this out I believe. I was using the same context for two
packages, one with a namespace and one without. This was causing the
context confusion, since the final Object graph I was marshalling might
have contained Objects from the non-namespaced package.

In addition, it was vital that my schema document had
elementFormDefault="qualified" included, otherwise it looked like JAXB
would only mark the root element with a prefix and nothing else.

This was somewhat tricky, but in the end it was pretty correct behavior
I would assume.

-bp


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