Are there any Code Generators that would take a well-formed XML document, and write out an XSD schema based on how the XML document is structured?
The XSD.exe utility (which is installed with Visual Studio) is capable of creating an XSD file from an XML file.
Here's the link on MSDN
I believe it may also part of the .NET SDK, meaning you would not need a full-blown Visual Studio installation.
Visual Studio does it pretty well too... Open XML file.. Choose 'Generate Schema' Command from XML menu
I am a little late to the part, but I find that http://www.bware.biz/DotNet/Tools/CodeXS/WebClient/GenerateInput.aspx">Businessware Architects CodeXS is very good. I have found that it handles complex schema's much better.
I'm note sure it is useful. After all, it cannot infer everything: if an element is present in the XML document, how to know if it is mandatory or not?
Examplotron, to achieve a similar goal, relies, at least partly, on annotations.
Best Answer, bar none:
I pulled my hair out for a full 8 hr work day, got nowhere with all the crappy solutions out there (XSD, CodeXS, XSDObjectGen, and others) and am not interested in paying $400 for the stupid commercial tools just to do this.
Then I came across this codeplex project... WOW! Where was this all my life?
And the best part... its actively being worked on, right NOW (2009), not an abaondoned crust pile from 2004 or some lame thing.
Enjoy!