Sure. Your mapping file had a few errors, which I fixed like this:

<mapping>
   <description>Description of the mapping</description>
  <!-- mapping for class Outer -->
   <class name="xml.namespace.Outer">
      <map-to xml="Outer" ns-uri="http://www.abc.com/outer";
ns-prefix="ns" />
      <field name="zup">
         <bind-xml name="zup" node="element" />
      </field>
      <field name="inner" type="xml.namespace.Inner">
         <bind-xml name="Inner" node="element" />
      </field>
   </class>

  <!-- mapping for class Inner -->
   <class name="xml.namespace.Inner">
      <map-to xml="Inner" ns-uri="http://www.xyz.com/inner";
ns-prefix="ns1" />
      <field name="foo">
         <bind-xml name="foo" node="element" />
      </field>
      <field name="bar">
         <bind-xml name="bar" node="element" />
      </field>
      <field name="baz">
         <bind-xml name="baz" node="element" />
      </field>
   </class>
</mapping>

Please note that I used a different Java package in my tests.

Regards
Werner

[email protected] wrote:
> Hello list,
> 
> I want to marshal a class (resp. two classes, one containing the other)
> using two different namespaces as in the following example:
> 
> package ns1;
> public class Inner {
>   protected String foo;
>   protected String bar;
>   protected String baz;
>   public String getBar() { return bar; }
>   public void setBar(String bar) { this.bar = bar; }
>   public String getBaz() { return baz; }
>   public void setBaz(String baz) { this.baz = baz; }
>   public String getFoo() { return foo; }
>   public void setFoo(String foo) { this.foo = foo; }
> }
> 
> package ns;
> import ns1.Inner;
> public class Outer {
>   protected String zup;
>   protected Inner inner;
>   public Inner getInner() { return inner; }
>   public void setInner(Inner inner) { this.inner = inner; }
>   public String getZup() { return zup; }
>   public void setZup(String zup) { this.zup = zup; }
> }
> 
> At runtime, I have objects like this
> 
> Inner inner = new Inner();
> inner.setFoo("joe");
> inner.setBar("jim");
> inner.setBaz("bob");
> Outer outer = new Outer();
> outer.setInner(inner);
> outer.setZup("ray");
> 
> Now I want to marshal the object with Inner having a
> different namespace than Outer. I use the following
> mapping file:
> 
> <?xml version="1.0"?>
> <mapping>
>   <description>Description of the mapping</description>
>   <!-- mapping for class Outer -->
>   <class name="ns.Outer">
>     <map-to xml="Outer"
>             ns-uri="http://www.abc.com/outer";
>             ns-prefix="ns"/>
>     <field name="zup">
>       <bind-xml name="zup" node="element"/>
>     </field>
>     <field name="inner" type="ns1.Inner">
>       <bind-xml name="Inner" node="element"/>
>     </field>
>   </class>
> 
>   <!-- mapping for class Inner --> 
>   <class name="ns1.Inner">
>     <map-to xml="Outer"
>             ns-uri="http://www.xyz.com/inner";
>             ns-prefix="ns1"/>
>     <field name="foo">
>       <bind-xml name="foo" node="element"/>
>     </field>
>     <field name="bar">
>       <bind-xml name="bar" node="element"/>
>     </field>
>     <field name="baz">
>       <bind-xml name="baz" node="element"/>
>     </field>
>   </class>
> </mapping>
> 
> When marshalling as so:
> 
> Mapping m = new Mapping();
> m.loadMapping("map.xml");
> XMLContext context = new XMLContext();
> context.addMapping(m);
> Marshaller ms = context.createMarshaller();
> StringWriter sw = new StringWriter();
> ms.setWriter(sw);
> ms.marshal(outer);
> String xml = sw.toString();
> 
> I get the totally unexpected result:
> 
> <ns:Outer xmlns:ns="http://www.abc.com/outer";>
>   <ns:zup>ray</ns:zup>
>   <ns1:Inner xmlns:ns1="http://www.abc.com/outer";>
>     <ns1:foo xmlns:ns1="http://www.xyz.com/inner";>joe</ns1:foo>
>     <ns2:bar xmlns:ns2="http://www.xyz.com/inner";>jim</ns2:bar>
>     <ns3:baz xmlns:ns3="http://www.xyz.com/inner";>bob</ns3:baz>
>   </ns1:Inner>
> </ns:Outer>
> 
> As you can see: Inner has the namespace of it's parent and the
> children of inner have the Inner-namespace all with a new prefix.
> 
> What's going on here? This result is totally bogus.
> 
> What I want to have is the following:
> <ns:Outer xmlns:ns="http://www.abc.com/outer";>
>   <ns:zup>ray</ns:zup>
>   <ns1:Inner xmlns:ns1="http://www.xyz.com/outer";>
>     <ns1:foo>joe</ns1:foo>
>     <ns1:bar>jim</ns1:bar>
>     <ns1:baz>bob</ns1:baz>
>   </ns1:Inner>
> </ns:Outer>
> 
> Any help here?
> 
> Greetings
> 
> --Stefan
> 

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to