Using xsd to generate XML in .net

I work in a .net application where we need to generate XML files on the fly based on a dataset extracted from db. The XML schema should be based on the provided xsd. I would like to know if there is a way to bind or bind a dataset or each datarow with xsd. I do not know if this can be done at all, or I can think about using XSD from the wrong point of view. If I am mistaken, correct me and let me know about the best way to link the data obtained from db with a predefined schema. Thanks.

Update. If my perspective on xsd is wrong, follow up on how xsds are used (or maybe give me some useful links).

+6
xml xsd
source share
2 answers

In addition to the solution Joel Kohorn proposed - to generate typed datasets or business objects from XSD - let me add a few other approaches:

  • If you use a database that supports an XML type, such as Oracle or MS SQL Server, you can build XML directly in your SQL queries and get XML directly from the database, bypassing the population of the data set.
  • If your database schema is not directly mapped to XSD data, that is, you already have a typed dataset or a set of XML serializable business objects, and these objects are serialized to XML that does not conform to XSD, you are provided with XSLT to convert your XML into another XML document that will match this XSD.
+1
source share

Use a schema document as a parameter to the command line. The xsd.exe program, which is part of the visual studio, for creating class files or typed datasets that you can include in your project / solution. These classes or datasets can be serialized in xml and will correspond to the schema document that you used to create them.

The only problem is that it is not dynamic: you cannot wait until the runtime receives the schema files. But nothing is built there that supports it otherwise.

+3
source share

All Articles