<p>I'm working in a .net application where we need to generate XML files on the fly based on the dataset retrieved from the db. XML schema should be based on a xsd provided. I would like to know is there any way to bind or associate a dataset or each datarow with the xsd. I dont know whether it can be done at all or i may be thinking usage of XSDs at a wrong perspective. If i'm wrong please correct me and let me know of the best way to associate a data retrieved from db to a predefined schema.Thanks.</p>

<p>Update: If my perspective on xsd is wrong please shed some light on how xsds are used(or perhaps point me to some useful links).</p>

[{'answer_id': 76041, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 2, 'selected': False, 'text': "<p>Use the schema document as a parameter to the command line xsd.exe program included with visual studio to generate class files or typed datasets that you can include in your project/solution.  These classes or datasets can be serialized to xml and will conform to the schema document you used to create them.</p>\n\n<p>The only problem with this is that it's not dynamic:  you can't wait until runtime to get the schema files.  But there's nothing built in that supports this otherwise.</p>\n"}, {'answer_id': 76368, 'author': 'GregK', 'author_id': 8653, 'author_profile': 'https://Stackoverflow.com/users/8653', 'pm_score': 2, 'selected': True, 'text': "<p>In addition to the solution suggested by Joel Coehoorn -- generate typed datasets or business entities from XSD -- let me add a couple of other approaches:</p>\n\n<ol>\n<li>If you use a database that supports XML type like Oracle or MS SQL Server, you can construct XML right in your SQL queries and retrieve XML directly from the database bypassing population of dataset.</li>\n<li>In case your database schema is not directly mapped to the given XSD, i.e. you already have a typed dataset or a set of XML-serializable business objects and those objects are serialized into XML that doesn't conform to XSD you're provided with, then you can use XSLT to transform your XML to another XML document which will be compliant with the given XSD.</li>\n</ol>\n"}]
['https://Stackoverflow.com/questions/75935', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3113/']