I have an xml file that I would like to generate a c# class for. Is there any quick and easy way to do this? I don’t have a schema to go with my xml file, it’s just raw xml. Any ideas?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
All code generation tools that I know will require a schema – but you can easily create one from your XML data file.
You can use
xsd.exeto infer a XML schema from the XML data file:This will create a
yourdata.xsd. Of course, xsd.exe can only be guessing – pretty good sometimes, not so good other times. You might want to check (and possibly modify) the schema before proceeding.(You can do the same in Visual Studio: load the XML file, and from the XML menu, choose “Create schema”).
From that schema, you can then create serializable classes:
This will create a
yourdata.csfile that contains a C# class that can be serialized into and deserialized from your XML data files.Marc