I get multiple XSDs from various clients and I need to give them the data in XML format conforming to the XSD that they have provided. I already have written a code to dynamically create and compile a class from XSD using codedom, System.Reflection and codeprovider.
Now my plan is to get data from database through multiple queries and map the fields to the properties of the dynamic class created and serialize it. I am looking for a generic way of mapping these fields, which can be used for any type of xsd and by just mapping the fields it will serialize and gives XML file. As for the queries I am putting them in the config file. Is a generic solution do-able? Any ideas or pointers on how to go about it?
I get multiple XSDs from various clients and I need to give them the
Share
I was able to resolve this. Here are the steps I used: I first created an in-memory run time assembly from xsd using reflection and codedom.compiler with serializable attributes. Using the reflection I created instance of the classes in that assembly and assigned properties from the data I got from database. This class I forwarded to another method that serializes takes an object and serializes it to xml.
As far as the mapping, I made sure that the database column names needs to be matched with the xml attribute names and with that I was able map and invoke them.
Here is the snippet:
Then pass myClass object to serialize method that accepts object type and that’s it
For this, now I am planning to add a UI piece where the mappings like “ForexRates” are saved in the database and it would then open to any of the xsd types.
Thanks very much for you responses.