Patrick Wright wrote:
>
> Hi
>
> I'm trying to understand how Castor processes namespace mappings declared
> in a mapping file. It seems the documentation is incomplete.
>
> What I would like to know is:
> 1) under what circumstances Castor will add a ns1:, ns2:, etc. on its own
>
When it finds a namespace uri but no mapped prefix.
> 2) why does Castor ignore a ns-prefix assignment on a map-to for nested
> objects?
This I'm not sure of, I'll have to see an example.
>
> 3) when will Castor default to using the ns-uri for exolab? i am seeing
> this happen
This can happen when you declare the exolab namespace as the default
namespace in the mapping file, because the name attribute for bind-xml
is a QName, so the default namespace will be used for any names without
a prefix defined.
Eg:
<mapping xmlns="http://castor.exolab.org/ ...
xmlns:foo="http://foo.acme.org">
...
<class name="...">
<field ...>
<bind-xml name="foo:bar"/>
<!-- exolab namespace will be used here because exolab namespace has
been
mapped as the default namespace uri -->
<field ...>
<bind-xml name="bar"/>
...
</mapping>
>
> I can upload a sample if you need more detail.
>
> What is happening is, depending on whether or not I include an ns-prefix,
> Castor is a) adding a nsx: namespace for nested objects, elements,
> attributes and b) using the castor/exolab URI even if I specify my own in
> map-to, again for nested objects.
>
> I did find a reference to this on the Castor mailing list archives.
>
> What I would like:
> namespace only applied for top/root element
> no nsx: namespaces anywhere
You can declare the default namespace on the Marshaller:
myMarshaller.setNamespaceMapping("", "ns-uri");
--Keith
>
> It seems from just reading the mailing list that one option is to declare
> the namespace for each class mapping, xmlns:zoo="myuri", then to
> explicitly state the namespace for each bind-xml element (for attributes
> and elements).
>
> >From the documentation, I had thought I only needed to do this in each
> map-to element.
>
> One problem is that I will sometimes marshall from different points in my
> graph of objects, e.g.
>
> Zoo contains Habitats which contain Animals
>
> I may marshall an entire Zoo, a single Habitat (with animals) or an Animal.
>
> If I can pull together enough information on this, I would be glad to add
> it to the FAQ.
>
> Many thanks--Castor is a great tool.
> Patrick
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev