Hi Keith,

I tried out your suggestions but having a little trouble getting them to
work, hope you can help. I am trying to achieve just one default
namespace declaration at the document root:

<root xmlns="http://my.org/foo";>
  <foo>
  </foo>
</root>


Approach 1
----------
<class  name="Foo">
   <map-to ns-uri="http://my.org/foo"/>
   ...
</class>

This almost works but it produces xmlns="" attributes for all nested
simple elements. For example:

<root xmlns="http://my.org/foo";>
  <foo>
    <bar xmlns="">hello</bar>
  </foo>
</root>

Approach 2
----------
<mapping xmlns:foo="http://my.org/foo";>
  ...
</mapping>

Produces an empty namespace at the root level and no other namespace
declarations within the document:
<root xmlns="">
  <foo>
  </foo>
</root>

Approach 3
----------
Take out the prefix in the <mapping> element.
<mapping xmlns="http://my.org/foo";>
  ...
</mapping>

Produces an empty namespace at the root level and namespace declarations
within all elements in the document:
<root xmlns="">
    <ns1:foo xmlns:ns1="http://my.org/foo";>
       ...all nested elements are prefixed with ns1 ...
    </ns1:foo>
</root>

-----Original Message-----
From: Keith Visco [mailto:[EMAIL PROTECTED]] 
Sent: Sunday, February 16, 2003 1:57 AM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] Namespaces with Castor



Hi Mike, 

You can add namespaces to Castor in a few ways.

In your mapping file do the following:

<class  name="...">
   <map-to ns-uri="http://my.org/my-namespace"; ns-prefix="..."/>
   ...
</class>

You can also do the following:

<mapping xmlns:foo="http://my.org/foo";>
  <class name="org.my.Foo">
     <field name="data" type="string">
        <bind-xml name="foo:data"/>
     </field>
  </class>
</mapping>

If you just want to declare a prefix for a namespace you can do the
following:

Marshaller m = new Marshaller(...);
m.declareNamespace("foo", "http://my.org/foo";);


Hopefully that answers your questions. If you need further assistence,
just let us know.

Thanks,

--Keith


Mike Denning wrote:
> 
> Can anyone provide me with instructions on how to define namespaces 
> and namespace prefixes when marshalling xml byte streams from beans 
> using Castor?
> 
> I assume you would put something either in castor.properties or your 
> mapping file....
> 
> thanks in advance....
> 
> Michael D. Denning
> Systems Programmer
> NC Department of Justice
> Information Technology Division
> 919-716-1062
> 
> -----------------------------------------------------------
> 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

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

Reply via email to