Hi James,

As a work-around, in the mapping file, just remove the DOCTYPE
declaration, this will prevent the XML parser from validating the
NMTOKEN. 

--Keith


James Elson wrote:
> 
> Hi,
> 
> We've recently upgraded from Castor 0.9.4 to 0.9.5.3 and hit a problem regarding
> namespaces. Our output documents need a namespace and to keep things tidy, this
> was being set as the default namespace so the output documents looked like
> this:
> 
> <foo xmlns="http://foo.bar.com/ns/something";
>      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>      xsi:schemaLocation="http://foo.bar.com/ns/something something.xsd">
> 
>    <myThing att="whatever">
>       <and>so on</and>
>    </myThing>
> </foo>
> 
> We achieved this by setting the namespaceMapping for the default namespace as
> follows:
> 
> marshaller.setNamespaceMapping("", "http://foo.bar.com/ns/something";);
> marshaller.setSchemaLocation("http://foo.bar.com/ns/something something.xsd");
> 
> This used to work fine but the new version resets the default namespace to "" so
> the resulting document looks like this:
> 
> <foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>      xsi:schemaLocation="http://foo.bar.com/ns/something something.xsd"
>      xmlns="">
> 
>    <myThing att="whatever">
>       <and>so on</and>
>    </myThing>
> </foo>
> 
> i.e. the namespace URI is an empty string.
> 
> An earlier post from Keith implied this was by design (and I see there was a bit
> of code added to Marshaller.java to handle this specific case). The solution it
> seems is to add the namespace to the mapping file, so that the elements
> generated have the correct namespace and hence would map to the prefix
> specified in the setNamespaceMapping() calls.
> 
> So, I tried to do this using the ns-uri attribute of the <map-to> element:
> 
> <mapping>
>     <description>myThing mapping</description>
>     <class name="com.bar.myThing">
>         <map-to xml="myThing" ns-uri="http://foo.bar.com/ns/something"; />
>         ...
>     </class>
> </mapping>
> 
> However, this has hit a problem pretty quickly. The mapping.dtd file specifies
> that the attribute ns-uri must be an NMTOKEN. The "http://"; style URI doesn't
> conform to the grammar for NMTOKEN (those slashes). So the mapping file doesn't
> parse:
> 
> SAXException: Parsing Error: Attribute value "http://foo.bar.com/ns/something";
> of type NMTOKEN must be a name token.
> 
> That makes sense given the DTD. So, how *should* I be using this attribute? The
> examples I've seen that specify this attribute also use http:// style URIs so
> how do they parse?
> 
> I've had a dig around in the mail archives and documentation, but to no avail.
> I'm sure I must be missing something obvious, so any help would be most
> appreciated.
> 
>   James
> 
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-user



----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-user

Reply via email to