Skip to content

Generating xml dataset classes programmatically

Roy

Asked Jun 14, 2007, 4:51 PM EDT1 answer
Share
LinkedInX

In the VS command prompt that is part of the VS SDK you can enter the following to generate an xsd file from an xml file:

      xsd XMLfilename.xml

This will generate an xsd file with the same name as the xml file

Then you can enter:

    xsd [.xsd file generated from above]  /d  /language:CS

This will generate a .cs file with the same name as the .xml and .xsd from above.  In your program you can then load the xml file into a dataset in memory and query it programmatically using the class that was generated for that xml file.

I am searching for a way to perform the above steps programmatically rather than using the command prompt.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0
    If the xsd tool is in your path, you can run the xsd tool programmatically using

    System.Diagnostics.Process.Start("xsd.exe", "<params>");

    Another tact you could take is create an xslt file that does the conversion to xsd, and use the xslt transform capability built into .NET to use the xslt transform file programmatically.
    0