tags:

views:

191

answers:

3

What avenues are there for using an XSD to generate message instances? I seem to remember reading about generating classes from XSD, but can't find anything specific now. I know you can generate classes and datasets from XSD, but I'm looking for a pattern for automating the actual generation of the messages.

BTW, SO is my knowledge sharer of choice, not Google.

A: 
xsd /c yourschema.xsd > yourschema.cs
leppie
I'm actually looking for a way to generate message _instances_, so it seems more useful to generate a typed dataset, which I can populate with message data. I was wondering if there were any other ways.
ProfK
+1  A: 

You can also create an XSD from XML samples with xsd.exe. Start the visual studio command prompt and use it to create an xsd from an xml sample. Then you can, as leppie shows, use xsd.exe to create a typed data set from that XSD. I wouldn't recommend doing this blindly, but it can certainly help when using a third party xml service.

XML -> XSD -> TypedDS by using xsd.exe.

ccook
A: 

Visual Studio XSD should be the first port of call. It will generate classes which you can serialise and deserialize the xml documents to/from.

XSD will work for "simple" schemas, there are plenty which it cannot cope with.

NB: if you schema imports other schema files you need to include those schema files on the command line as well.

Other code generation from schema files tools include XMLSpy, Enterprise Architect. Worth looking at if XSD fails your requirements.

Aussie Craig