Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use xsd.exe /c output

Tags:

c#

xml

xsd.exe

I tried using xsd.exe to convert an .xsd file into a C# class. It worked, but I'm still not quite sure how to use this class. It has several class-level attributes but the most interesting is System.Xml.Serialization.XmlTypeAttribute. Which class uses that attribute?

Is there a simple way to turn an instantiation of this class into a string of XML?

like image 365
User1 Avatar asked Feb 09 '10 20:02

User1


1 Answers

Super straight-forward. I love the xsd tool. I have taken some liberties below.

//From xml to object
YourRootType inst = new XmlSerializer(typeof(YourRootType)).Deserialize(XmlReader.Create("some.xml"));

//From object to xml
Using(FileStream fs = new FileStream("some.xml", FileMode.Create))
   new XmlSerializer(typeof(YourRootType)).Serialize(fs, inst);
like image 166
Grant Back Avatar answered Oct 13 '22 11:10

Grant Back