I speak better in examples :)
See attachment for 2 scenarios.
To get the scenario you want you have to leave the .betwixt file in and
for a different format you can leave the .betwixt out...

Hope it is clear a bit what is done there. The javadoc is pretty much
up-to-date though, so you look in the javadoc what is done there (or the
website)

Mvgr,
Martin

On Wed, 2003-01-29 at 04:52, Desmond Wong wrote:
> What should I do if I want use betwixt to print out
> the xml like this:
> <Student>
>    <Name string="John"/>
>    <Age no="14"/>
>    <Address string="Asia"/>
> </Student>
> 
> Thanks
> 
> __________________________________________________
> Do You Yahoo!?
> Everything you'll ever need on one web page
> from News and Sport to Email and Music Charts
> http://uk.my.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

<info>
  <element name="Student">
    <element name="Name">
      <attribute name="string" property="name"/>
    </element>
    <element name="Age">
      <attribute name="no" property="age"/>
    </element>
    <element name="Address">
      <attribute name="string" property="address"/>
    </element>
  </element>
</info>
package org.apache.commons.betwixt.tmp;

import java.beans.IntrospectionException;
import java.io.IOException;
import java.io.StringWriter;

import org.apache.commons.betwixt.XMLIntrospector;
import org.apache.commons.betwixt.io.BeanWriter;
import org.apache.commons.betwixt.strategy.CapitalizeNameMapper;
import org.xml.sax.SAXException;

/**
 * 
 * @author Martin van den Bemt
 * @version $Id: $
 */
public class Student
{
    private String name;
    private String age;
    private String address;
    
    /**
     * Constructor for Student.
     */
    public Student()
    {
        super();
    }
    
    /**
     * Returns the address.
     * @return String
     */
    public String getAddress()
    {
        return address;
    }

    /**
     * Returns the age.
     * @return String
     */
    public String getAge()
    {
        return age;
    }

    /**
     * Returns the name.
     * @return String
     */
    public String getName()
    {
        return name;
    }

    /**
     * Sets the address.
     * @param address The address to set
     */
    public void setAddress(String address)
    {
        this.address = address;
    }

    /**
     * Sets the age.
     * @param age The age to set
     */
    public void setAge(String age)
    {
        this.age = age;
    }

    /**
     * Sets the name.
     * @param name The name to set
     */
    public void setName(String name)
    {
        this.name = name;
    }
    
    public static void main(String args[])
    {
        Student student = new Student();
        student.setAddress("Address");
        student.setName("name");
        student.setAge("15");
        StringWriter out = new StringWriter();
        BeanWriter writer = new BeanWriter(out);
        writer.enablePrettyPrint();
        writer.setWriteIDs(false);
        XMLIntrospector intro = new XMLIntrospector();
        intro.setElementNameMapper(new CapitalizeNameMapper());
        writer.setXMLIntrospector(intro);
        try
        {
            writer.write(student);
        }
        catch (IOException e)
        {
        }
        catch (SAXException e)
        {
        }
        catch (IntrospectionException e)
        {
        }
        System.out.println(out.toString());
    }

}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to