Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to create a Java file on the fly

802707Oct 3 2010 — edited Oct 4 2010
HI guys,

I would like to create a Java file based on the information from an XML file. I would like to read the info from an xml and generate a class and it's method.


e.g
<person>
  <name>croc</name>
  <surname>crocky</surname>
  <age>12</age>
</person>
then it should generate:
public class Person {
private String name = "";
private String surname = "";
private int age = 0;

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

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the surname
     */
    public String getSurname() {
        return surname;
    }

    /**
     * @param surname the surname to set
     */
    public void setSurname(String surname) {
        this.surname = surname;
    }

    /**
     * @return the age
     */
    public int getAge() {
        return age;
    }

    /**
     * @param age the age to set
     */
    public void setAge(int age) {
        this.age = age;
    }
}
I know how to read information from an xml. what i need is to generate a class and it's methods.

Thanks
Croc85
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 1 2010
Added on Oct 3 2010
11 comments
741 views