commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Desmond Wong <desmond_won...@yahoo.com>
Subject Re: commons betwixt
Date Thu, 30 Jan 2003 02:55:00 GMT
Thanks for your help and I am already compiled and run
your source code that you attach in the email and the
result is like this:
<Student>
  <Address>Address</Address>
  <Age>15</Age>
  <Name>name</Name>
</Student>

But the result is different for what I want to do.
This is the result that I want:
<Student>
  <Address name="Address"/>
  <Age no="15"/>
  <Name string="name"/>
</Student>

I want to print out the parent element and then the
child elements with attributes. So, what should I do?


 --- Martin van den Bemt <mllist@mvdb.net> wrote: > 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:
> commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> commons-user-help@jakarta.apache.org
> > 
> > 
> 
> > <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:
> commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
commons-user-help@jakarta.apache.org 

__________________________________________________
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

Mime
View raw message