0

Using java, I am trying to read XML nodes and attributes, and then create a specific language (smv language) file by using those nodes and the relation between the nodes. Lets say I have an XML classes as following (please don't mind the xml structure and/or java code, it is just for clarifying the case) Lets say the xml file is Person.xml

<person>
<name type='string'>John</name>
<age type='int'>25</age>
</person>

Then I will read that XML file and create a proper java classes lets say Person.java,

class Person
{
string name="John";
int age=25;
}

I just wondered, do you know is there any specific pattern or any good aproach to manage such a project? What would you advice for that case?

Many Thanks

Memin
  • 3,788
  • 30
  • 31
  • Algorithm != "design pattern". You pretty much just have to determine what you want your output to be, how you want it to relate to the input, then it's up to you to define what the input should look like and how it should be translated. It really depends on your requirements. I suggest first coming up with a concrete idea of exactly what you want to accomplish, and how the desired output can be represented in a tree-like structure; the XML schema will follow from that, then you just implement the translation. BTW, you can use `DocumentBuilder` to parse XML and navigate it with DOM methods. – Jason C Mar 14 '14 at 00:28
  • Also it's up to you to determine how abstract you really want to get. For example, your input could be `John25`, or it could be `John25`, or whatever, and the representative output types language-specific. But then again, that may not be specific enough for your particular application. – Jason C Mar 14 '14 at 00:30
  • Thanks Jason C, your advises are useful. – Memin Mar 14 '14 at 00:37

1 Answers1

1

The process of converting a programming language object to a textual representation is called serialization or marshalling. The reverse (text to object) is called deserialization or unmarshalling.

There are several popular Java tools to accomplish this. See: XML serialization in Java?

Community
  • 1
  • 1
jaco0646
  • 15,303
  • 7
  • 59
  • 83