Hi ,
   I used the marshalling technique. It is creating a correct XML Document
for simple object. If it contains another object ,
it is failing to generate data for nested object, eventhough it is creating
a tag .
  My code is as follows:
   
  /*
 * Person.java
 *
 * Created on July 11, 2002, 2:23 PM
 */

/**
 *
 *
 */

import java.util.Date;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;

import java.io.*;

/**
 * An simple person class
 */
public class Person implements java.io.Serializable {
    
    /**
     * The name of the person
     */
    private String name = null;
    
    /**
     * The Date of birth
     */
    private Date dob = null;
    
    private TestPerson testPerson = null;
    /**
     * Creates a Person with no name
     */
    public Person() {
        super();
    }
    
    /**
     * Creates a Person with the given name
     */
    public Person(String name) {
        this.name  = name;
    }
    
    /**
     * @return date of birth of the person
     */
    public Date getDateOfBirth() {
        return dob;
    }
    
    /**
     * @return name of the person
     */
    public String getName() {
        return name;
    }
    
    /**
     * Sets the date of birth of the person
     * @param name the name of the person
     */
    public void setDateOfBirth(Date dob) {
        this.dob = dob;
    }
    
    /**
     * Sets the name of the person
     * @param name the name of the person
     */
    public void setName(String name) {
        this.name = name;
    }
    
    public TestPerson getTestPerson()
    {
       return  this.testPerson ; 
    }    

    public void setTestPerson(TestPerson testPerson)
    {
        this.testPerson = testPerson;
    }    



/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
 
    try{
    // Create a new Person
    System.out.println("Started......");    
    Person person = new Person("Ryan 'Mad Dog' Madden");
    person.setDateOfBirth(new Date(1955, 8, 15));
    person.setTestPerson(new TestPerson(15, "TestName"));
    
    System.out.println("test person:"+ person.getTestPerson());
    // Create a File to marshal to
    FileWriter writer = new FileWriter("E:\\msr\\test.xml");
    
    // Marshal the person object
    Marshaller.marshal(person, writer);
        
        // Create a Reader to the file to unmarshal from
//FileReader reader = new FileReader("E:\\msr\\test.xml");

// Marshal the person object
//person = (Person)Unmarshaller.unmarshal(Person.class, reader);
//System.out.println("Name..."+person.getName());
    System.out.println("Ended.......");  
    }
    catch(Exception ioe)
    {
    }    
    
}
}

class TestPerson implements Serializable
{
    int id ;
    String name ;
    
    public TestPerson()
    {
    }
    
    public TestPerson(int id , String name )
    {
        this.id = id;
        this.name = name;
    }
    
    public String toString()
    {
        return this.id + "," + name;
    }    
    public int getId()
    {
       return id;   
    }    
    public void setId(int id )
    {
       this.id = id;   
    }    
     public String getName()
    {
       return name;   
    }    
    public void setName(String name )
    {
       this.name = name;   
    }    
}    
  
output XML adjustment :
-----------------------

<?xml version="1.0" encoding="UTF-8" ?> 
- <person>
  <test-person /> 
  <name>Ryan 'Mad Dog' Madden</name> 
  <date-of-birth>3855-09-15T00:00:00.000-04:00</date-of-birth> 
  </person>

-----Original Message-----
From: Mickael Guessant [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 17, 2002 9:40 AM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] Creating XML Document For Complex object



  Just try to marshal one of your object tree and see if the
default behaviour matches your needs ;-)

FileWriter xmlWriter = new FileWriter("test.xml");
Marshaller.marshal(bean, xmlWriter);

"Muttineni, Srinivas" a �crit :
> 
> Hi ,
>      I am trying to use castor to generate an XML documnt for complex
> objects that contain objects , collection of objects and so on. I am
unable
> to get the documentation for that.  Could you please tell me  how we can
do
> this ?
> 
>       Thanks  a lot.
> 
>            Srinivas  Muttineni
> 
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-dev

-- 
Mickael Guessant
Consultant Architecture Distribu�e
Fi System France - http://www.fisystem.com
mailto:[EMAIL PROTECTED]

----------------------------------------------------------- 
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