0

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

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by Darryl.Burke
0

Where do you want to create the source? As a disk file or as a String?
A disk file could use the javac command to create the class file, the String could be compiled by a JavaCompiler object.

What questions do you have about creating a java source?
Why do you think the syntax would be different for your project than if you typed the source in using an editor?

Edited by NormR1: n/a

0

Thanks very much for quick response.
I would like to create it as a disk file.

I know the syntax would not be different. The thing is, I don't want to keep on editing the class time and again. if I have it reading an xml file it becomes easily managable.

Most of the methods are going to be List, and they'll be getting information from the database.

0

Can you explain the design for your project?
I don't know what you mean by "keep on editing the class".

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.