There are a lot of good ways to handle xml within software. The programmers like XML serializing of classes very often. The XML purists like to define XSD (schema). And I sometimes like the idea to define what a want by a sample and reverse engineer the XSD and import the XSD to the model and of course generate the classes (in my case often C#) from the XSD.

Step 1 – define what you want as a result

That is the main cause why I personally like my approach ­čśë – you define, what you expect as a result. The better the sample the better the reverse engineering result to generate the XSD. In my sample I use CompaniiLevels containing CompaniiLevel containing Buttons containing Button and some simple elements like ID or Name.

Step1SampleXML

Step 2 – Generate the XSD

I prefer to use Visual Studio built-in XSD generator – you have to open the XML and then the menu becomes visible. The XSD is good-enough.

Step 3 – Model and documentation

In Enterprise Architect – you can import XSD, modify and enhance┬áit in a modelling way, generate documentation and so on. In my sample I’ve used only nested classes so the model structure is fine, but the diagrams do not have nested links by default – so for my documentation I enhance the model with dependency links.

Nested Classes in Enterprise Architect’s project browser:

Step3ProjectHierachy

Diagram View after modification and including dependency links:

Step3Dependencies

Step 4 – Generate classes using XSD2Code

In the past I always used XSD.exe (part of .net framework) – but a much powerful solution is: http://xsd2code.codeplex.com/┬áthe only thing you should know: turn on the GenerateXmlAttributes Option if you want to serialize/deserialize data it is a must.

Of course this tool supports a lot of stuff that reduces work – like┬ásave/load from files,┬ádata binding, …