I want to create XML file with data(data is from database) using existing XSD file. Please guide me how to do this in C#
Asked
Active
Viewed 1,727 times
-4
-
you create an xml file from C# classes (generated with XSD) and validate it against the XSD. I think google will give you a some directions. (google: xml C# xsd will prolly give you a nice kick start) – bas Mar 11 '13 at 20:27
-
2[I wish people would search first!](http://stackoverflow.com/questions/6530424/generating-an-xml-file-using-xsd-file). – Brian Mar 11 '13 at 20:28
-
Sorry, from 2days am checking in net. am getting soluntion to use xsd.exe to get xml file and that i have to include in my VS project. but am getting confused how to create xml file by using that and putting data into that – Anusha.G Mar 11 '13 at 20:45
-
-1: "I'm getting confused" is not enough to explain problems you are facing - and it is even harder when question does not have any sample code (i.e. from comments it looks like you can't save XML to a file, but it is not clear if it is the actual road block you are hitting) – Alexei Levenkov Mar 11 '13 at 20:53
1 Answers
1
Here's one way:
- Use
xsd.exe
to create a set of class definitions from your schema. - Populate instances of those classes from the database.
- Use
XmlSerializer
to serialize those instances to XML.

D Stanley
- 149,601
- 11
- 178
- 240
-
Yes i used xsd.exe for creating xml file,but its giving error saying "can only generate one of classes or datasets" and not able to find where the xml will get saved – Anusha.G Mar 11 '13 at 20:40
-
Did you read the documentation on how to use XSD.EXE? You can't specify both `/classes` and `/dataset`. The output will be in the current folder unless you use the /o flag. And it doesn't create XML files - it creates .CS (class) files. – D Stanley Mar 11 '13 at 21:00