From raw xml (no schema) to C # class?

I have an xml file for which I would like to generate a C # class. Is there a quick and easy way to do this? I have no schema to go with my xml file, it's just raw xml. Any ideas?

Thank.

+2


source to share


1 answer


All code generation tools I know will require schemas, but you can easily generate them from an XML data file.

You can use xsd.exe

to output XML schema from XML data file:

xsd.exe yourdata.xml 

      

This will create yourdata.xsd

. Of course, xsd.exe can only guess - pretty good sometimes, not so good at other times. You can check (and possibly change) the schema before proceeding.

(You can do the same in Visual Studio: load an XML file and choose Create Schema from the XML menu).



From this schema, you can create serializable classes:

xsd.exe yourdata.xsd /classes

      

This will create a file yourdata.cs

that contains a C # class that can be serialized and deserialized from your XML data files.

Mark

+5


source







All Articles