3

I just started a project where I need to create a class to map all XML attributes from an XSD file. For those ones with a few attributes, it can be done manually. For those with a lot of attributes it will take some time to create the class.

I found I can use XSD tool link to achieve this. In fact, I was able to generate a class from an XSD file. However, it was using the command prompt in Windows.

CMD line:

C:\XSD path..\xsd myXSDFile.xsd /classes

where XSD path for SDK 8 and later (link for more info)

There is an an additional FX version subdirectory:

%programfiles(x86)%\Microsoft SDKs\Windows\{ver}\bin\{FXVer} Tools

Any one knows if the same can be achieve from Mac OS? Is there a way to use XSD tool in this OS? or a similar tool that we can use?

MikePR
  • 2,786
  • 5
  • 31
  • 64

2 Answers2

3

XSD.exe has not been ported over to .NET Core unfortunately (see this github issue: https://github.com/dotnet/runtime/issues/1391). They have acknowledged the issue (which was first raised in 2016), but the last update on it was Dec 2019, so don't hold your breath.

However, there is another way to generate C# classes for an XSD using a tool called LinqToXsd, which is another Microsoft-created tool that began as .NET Framework-only, but was ported over to .NET Core 2 (see https://github.com/mamift/LinqToXsdCore). It can be invoked on any version of MacOS that supports .NET Core 2 and generates code that is .NET Standard 2.0-compatible.

First install .NET Core 2 for MacOS, then install LinqToXsdCore using the dotnet command:

dotnet tool install LinqToXsdCore -g

Then you can generate your C# classes using the command:

linqtoxsd gen "pathToFile.xsd"

You can find full instructions here: https://github.com/mamift/LinqToXsdCore/blob/master/LinqToXsd/README.md

mamift
  • 651
  • 7
  • 18
1

No idea if this is still relevant for anyone, but xsd is ported to Mac in the Mono Framework.

I just used it to transform some xsds. It is found under:

/Library/Frameworks/Mono.framework/Versions/Current/Commands/xsd

So simply install Mono Framework on your Mac (I already had it installed, and can't remember where I got it from...)

hbertsch
  • 367
  • 2
  • 12