Gregg- I know it's a hassle in the real world, but does explicitly defining the namespace in the mapping fix the problem? More specifically change:
<bind-xml name="items"/> to <bind-xml name="gl:items"/> where gl is the short version of the appropriately defined namespace. If you look at the Castor XML HOW-TO on validation you'll see that's how I had to declare everything to get it in the right namespace (not saying it should be this way, but it's what worked back when I wrote it). My guess is most of the elements correctly inherit the namespace from the class (via the ns-uri attribute), but the special processing done by container="false" doesn't. Stephen On 10/24/06, Fowler, Gregg E <[EMAIL PROTECTED]> wrote:
Hi, I'm having difficulty getting default namespaces to be generated properly in an output XML file for lists created using a container="false" field. Basically, I'm trying to generate XML like the following: <?xml version="1.0" encoding="UTF-8"?> <ServiceResponse xmlns="http://www.globallink.com/v1/service"> <items> <item><id>1</id></item> <item><id>1</id></item> </items> </ServiceResponse> I've tried creating a mapping file where either I specify the mapping only at the top level, or for each class. My problem is that I can't get the "items" list above (created by a container="false" field) to go into a proper namespace. The closest I can currently get is: <?xml version="1.0" encoding="UTF-8"?> <ServiceResponse xmlns="http://www.globallink.com/v1/service"> <items xmlns=""> <item><id>1</id></item> <item><id>1</id></item> </items> </ServiceResponse> Here is my mapping file: <?xml version="1.0" encoding="UTF-8"?> <mapping> <class name="com. globallink.data.ServiceResponse"> <map-to xml="ServiceResponse" ns-uri="http://www.globallink.com/v1/service" element-definition="false" /> <field name="items" type="com.globallink.data.Item" container="false" collection="array"> <bind-xml name="items"/> </field> </class> <class name="com.globallink.data.Item"> <map-to xml="item" /> <field name="id" type="string"> <bind-xml name="id"/> </field> </class> </mapping> And my java code: StringWriter writer = new StringWriter(); ServiceResponse response = new ServiceResponse (); Item[] items = new Item[2]; Item item; item = new Item(); item.setId("1"); items [0] = item; item = new Item (); item.setId("2"); items [1] = item; response.setItems(items); try { Mapping mapping = new Mapping(); mapping.loadMapping("castor.xml"); Marshaller marshaller = new Marshaller(writer); marshaller.setMapping(mapping); marshaller.marshal(response); System.out.println(writer.getBuffer().toString()); } catch (Exception e) { e.printStackTrace(); } } Any suggestions? Thanks, Gregg --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email
--------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email

