Consider this scenario: I've an XML file called person.xml with the following data in it.
<person>
<name>MrFoo</name>
<age>28</age>
</person>
If I want to read this XML into a Java object, I would be creating a Java bean called PersonBean (with getters/setters for the attributes) as:
class Person{
String name;
int age;
}
And I could use any APIs for reading the XML and populating the Java Bean.
But the real question here is, suppose if the structure of the XML file changes, i.e. if an new attribute 'email' is added to the XML file, then I have to modify the Java Bean also to add a new attribute. But, I want to avoid changing the Java code even if the XML structure changes.
So, what I'm trying to do is, I'm creating another XML file called PersonStructure.xml with the content as:
<class name="Person">
<attributes>
<attribute>
<name>personName</name>
<type>java.lang.String</type>
</attribute>
... and it goes like this...
</attribute>
</class>
Is it possible to read the PersonStructure.XML file and convert it into Person.Java class file? The approach what I'm trying to do is correct or is there any other way to do the same?