I have a huge number of XML files and I need to convert them to C# classes so I can later deserialize them. I need to automate the XML files to C# class file conversion.
Note: The XML files are somewhat similar in structure but some introduce other attributes.
I have tried the following:
1. XSD
By using XSD included with visual studio, the whole process can be easily automated using C#. By making an XSD for each file and turning them to .cs this is possible. The problem is that the complexity of the XSD files raise problems and the conversion won't be correct. Deserialisation won't work due to the following error:
Cannot convert type 'AttributeName[]' to 'AttributeName'
This error is present for every attribute generated by the .xsd.
I have also tried generating an XSD for all the XML files and converting the XSD into C#. The deserialisation still doesn't work, this time marking all attributes as null.
2. Paste as Special (XML to C#)
Visual Studio offers quite a nifty feature and the deserialisation works with this. Yet I have no idea how I can automate this for every file.
3. XML2CSharp.com
This works too, but the problem remains the automation. I have quite a lot of files and I cannot do such process over and over again.
An ideal solution would be a convertToObject() function that makes a new C# object for the current XML file being accessed. I'm not sure how maybe I could automate the second method that I tried.