Preparation:
- Get an XSD file
- Generate the Classes from XSD using xsd.exe tool
Xml Serialization Process:
- Create a new instance of the object from the XSD e.g. login object
- Use XmlSerializer class to serialize the object and get the result back; you would just need some Factory methods
- Use the serialized data
Xml Deserialization Process:
- Get the xml as string
- Specify the type e.g. login
- Deserlialize the xml to the type specified using XmlSerializer class
- Use the deserialized object
Examples:
[TestMethod] [Ignore] public void Should_Generate_Xsd_For_Class() { const string Xsd = @"""C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\xsd.exe"""; // /t:{2} /outputdir:{3} var arguments = string.Format("{0} /t:{1} /outputdir:{2}", @"""C:\Tfs\Project\Trunk\Project\bin\Debug\ProjectName.dll""", "Namespace.ClassName", @"C:\Test"); Process.Start(Xsd, arguments); }
No comments:
Post a Comment