Hi Ramesh,

In type mode you need to supply the name of the top-level element,
because you are marshalling a Complex-Type and not an element. 

Change your code to look as follows:

Change the following line: 

> msg.marshal(sw);

to:

Marshaller m = new Marshaller(sw);
m.setRootElement("message");
m.marshal(msg);

--Keith

Ramesh Vishwanatham wrote:
> 
> Hi
> 
> We are using castor api to marshall and un-marshall based on castor's
> SourceGenerator. We are using org.exolab.castor.builder.javaclassmapping
> property as "type" instead of default "element". Because of this xml we
> are getting when we call marshall on the top level element class is
> incorrect. Only the top-level element name is corrupted. I am enclosing
> a sample xml schema, a test program and its output. We are using
> 0.9.3.9 version of the api and I checked with latest version also and
> the result is the same. I would like to know anyone suggest a solution
> for this problem. Thanks in advance.
> 
> Ramesh
> 
>   ------------------------------------------------------------------------
> <?xml version="1.0" encoding="utf-8" standalone="no"?>
> <xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
> 
> <xsd:simpleType name="OpRole_T">
>         <xsd:restriction base="xsd:string">
>                 <xsd:enumeration value="REQ"/>
>                 <xsd:enumeration value="RESP"/>
>         </xsd:restriction>
> </xsd:simpleType>
> 
> <xsd:complexType name="Content_T">
>         <xsd:sequence>
>                 <xsd:element name="id" type="xsd:string"/>
>                 <xsd:element name="name" type="xsd:string"/>
>         </xsd:sequence>
> </xsd:complexType>
> 
> <xsd:complexType name="Message_T">
>         <xsd:sequence>
>                 <xsd:element name="hdr" type="Hdr_T"/>
>                 <xsd:element name="content" type="Content_T"/>
>         </xsd:sequence>
> </xsd:complexType>
> 
> <xsd:complexType name="Hdr_T">
>         <xsd:sequence>
>                 <xsd:element name="id" type="xsd:string"/>
>                 <xsd:element name="role" type="OpRole_T"/>
>         </xsd:sequence>
> </xsd:complexType>
> 
> <xsd:element name="message" type="Message_T"/>
> </xsd:schema>
> 
>   ------------------------------------------------------------------------
> import cgwgen.*;
> import cgwgen.types.*;
> import java.io.*;
> 
> public class test1 {
>         public static void main(String [] av) throws Exception{
>                 Message_T msg = new Message_T();
>                 Hdr_T hdr = new Hdr_T();
>                 Content_T con = new Content_T();
>                 msg.setHdr(hdr);
>                 msg.setContent(con);
> 
>                 String hdr_id = "h1";
> 
>                 hdr.setId(hdr_id);
>                 hdr.setRole(OpRole_T.RESP);
> 
>                 con.setName("cname");
>                 con.setId("c1");
> 
>                 StringWriter sw = new StringWriter();
>                 msg.marshal(sw);
>                 System.out.println("xml::" + sw.toString());
>         }
> }
> 
>   ------------------------------------------------------------------------
> xml::<?xml version="1.0"?>
> <Message_T><hdr><id>h1</id><role>RESP</role></hdr><content><id>c1</id><name>cname</name></content></Message_T>

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

Reply via email to