C# Auto generation of class objects from XSD
I'm creating an xml file and have an XSD file to work against.
I'm sure I remember reading somewhere that C# can automagically create class objects when given an XSD. So if I have an address e开发者_StackOverflow社区lement in XML I can have a generated C# class that uses the xsd to create the required properties of the class.
e.g.<adress><postcode></postcode><phone></phone>
would map to a class called Address with properties postcode and phone.
Is this sort of thing possible or did I dream it?
use xsd.exe in the .net sdk.
use the /c switch to generate classes
See link from @Jason w
I had to use this when working with OFX. Be aware that if your xsd is complex, it will handle some cases in a funky way.
For instance some items get generated in a generic manner and will show up as
public class SomeTag
{
public object Item[] { get; set; }
public ItemCollection[] {get; set;}
}
public enum ItemCollection
{
SomeName,
SomeOthername,
AthirdYetExclusiveItem
}
Just be forewarned and well read...
精彩评论