Gregg- That implies to me that the container="false" logic isn't handling namespaces correctly. Since it's been an undocumented feature for several years now, I would hazard a guess that the code may not be as well vetted as the rest of Castor. I would suggest raising an issue in Jira and letting the devs take a look at it.
Stephen On 10/25/06, Fowler, Gregg E <[EMAIL PROTECTED]> wrote:
Hi, Thanks for the suggestion, but it didn't seem to help. I tried that and updated it to look closer to what you had in your validation example, as shown below. Mapping File -- <?xml version="1.0" encoding="UTF-8"?> <mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:g="http://www.globallink.com/v1/service" xmlns="http://castor.exolab.org" xsi:schemaLocation="http://castor.exolab.org/mapping.xsd"> <class name="com.globallink.data.ServiceResponse"> <map-to xml="ServiceResponse" ns-uri="http://www.globallink.com/v1/service" ns-prefix="g" element-definition="false" /> <field name="items" type="com.globallink.data.Item" container="false" collection="array"> <bind-xml name="g:items"/> </field> </class> <class name="com.globallink.data.Item"> <map-to xml="g:item" /> <field name="id" type="string"> <bind-xml name="g:id"/> </field> </class> </mapping> Produces -- <?xml version="1.0" encoding="UTF-8"?> <g:ServiceResponse xmlns:g="http://www.globallink.com/v1/service"><items><g:item><g:id>1</g :id></g:item></items></g:ServiceResponse> So "items" remains in the unqualified namespace. -- Gregg -----Original Message----- From: "Stephen Bash" <[EMAIL PROTECTED]>@STATESTREET Sent: Tuesday, October 24, 2006 1:48 PM To: [email protected] Subject: Re: [castor-user] Uncertain how to manage namespaces for lists (container=false) 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
--------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email

