1

I want to write code that creates an XSD based on a C# class.

I can't find information how to do this without using XSD.exe. Example class:

[XmlRoot("Sync")]
public class SyncFileSettings : ISyncSettings
{
   public SyncFileSettings(int pingIntervalSec, bool useCompression)
    {
        PingIntervalSec = pingIntervalSec;
        UseCompression = useCompression;
    }

    public int PingIntervalSec { get; set; }
    public bool UseCompression { get; private set; }
}
  • Please see ["Should questions include “tags” in their titles?"](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles), where the consensus is "no, they should not"! –  Apr 10 '15 at 11:06
  • @Andreas try to edit more than removing just a single "tag" from a title. – CodeCaster Apr 10 '15 at 11:08
  • possible duplicate of [How to create a XSD scheme from a class?](http://stackoverflow.com/questions/10017139/how-to-create-a-xsd-scheme-from-a-class) – Xstian Apr 10 '15 at 12:46

2 Answers2

3

how to generate xsd from class in code

Using XSD.exe.

without XSD.exe?

Why? Then you'll have to reinvent the wheel, or use a library.

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • @Vladimir I can't really follow what you're saying. You can just run XSD.exe from code. – CodeCaster Apr 10 '15 at 11:32
  • @Vladimir you're right, you're not allowed to redistribute XSD.exe. Why do you want your clients to generate an XSD though? Anyway to generate an XSD from a class is not trivial. Try searching for a library that allows you to do so. – CodeCaster Apr 10 '15 at 13:10
2

old thread, I know.

but now in the end of 2020 it was still hard for me to find a solution. I did, but it tooks a lot of time after I first found this thread. So - for all the guys finding just 'use XSD-tool' - there is a class XsdDataContractExporter in .net 5.0 now (System.Runtime.Serialization)

easy going, see microsoft XsdDataContractExporter Class. works fine!

happy coding :-)

astroni
  • 21
  • 1