Convert XSD files to C# Serializable Class

21,968

Solution 1

Be sure to put all referenced schemas on the cmd line.
When I do this, I get a bunch of warnings.

$ xsd /c listTheatersByPostalCode.xsd yahooMovie.xsd yahooMovieCredit.xsd yahooMovieMedia.xsd yahooMoviePhoto.xsd yahooMovieTheater.xsd yahooMovieTheaterAmenity.xsd yahooMultimedia.xsd yahooUser.xsd
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation. All rights reserved.
Schema validation warning: The global element 'urn:yahoo:movie:theater:TheaterList' has already been declared. Line 6, position 4.
Schema validation warning: The global attribute 'urn:yahoo:movie:theater:id' has already been declared. Line 7, position 4.
Schema validation warning: The complexType 'urn:yahoo:movie:theater:TheaterListType' has already been declared. Line 10, position 4.
Schema validation warning: The complexType 'urn:yahoo:movie:theater:TheaterType' has already been declared. Line 19, position 4.
Schema validation warning: The complexType 'urn:yahoo:movie:theater:PostalAddressType' has already been declared. Line 32, position 4.
Schema validation warning: The complexType 'urn:yahoo:movie:theater:AmenityListType' has already been declared. Line 55, position 4.
Schema validation warning: The complexType 'urn:yahoo:movie:theater:MovieListType' has already been declared. Line 65, position 4.
Schema validation warning: The complexType 'urn:yahoo:movie:theater:MovieType' has already been declared. Line 71, position 4.
Schema validation warning: The complexType 'urn:yahoo:movie:theater:ShowsType' has already been declared. Line 82, position 4.

Warning: Schema could not be validated. Class generation may fail or may produce incorrect results.

If I yank out yahooTheater.xsd from that list, it works fine.

I didn't even look at the XSDs but it seems to me that xsd.exe thinks some elements have been doubly defined. you may be able to manually reconcile that problem by combining yahootheater.xsd with yahooTheaterAmenity.xsd. Or, if you don't care about the amenity part, drop it.

Solution 2

Use the xsd.exe that comes with visual studio. iirc xsd /classes theschema.xsd

But since you tried that, what went wrong ?

Solution 3

Try out http://www.altova.com/download.html. It has a 30 day trial but it will convert xml xsd to classes. it also reverse engineers xml to make a xsd.

Solution 4

How about giving CodeXS a try? They normally work pretty well for me.

Share:
21,968
Miguel Ventura
Author by

Miguel Ventura

Updated on November 02, 2020

Comments