Blog Post : Using XmlSerializer with external serializable types
Listing 4 : Application Main() source code
  1. static void Main(string[] args)  
  2. {  
  3.     // Pretty-print (Altova terminology) the XML.  
  4.     AppData.Serializer.PrettyPrint = true;  
  5.     // TODO: Change the relative location as approriate..  
  6.     string testXmlInFilePath = @"..\..\schema\";  
  7.     // Read and de-serialize test.001.xml.  
  8.     string folderPath = Path.GetDirectoryName(Path.GetFullPath(testXmlInFilePath));  
  9.     string xml = ReadFile(Path.Combine(folderPath, "test.001.xml"));  
  10.     AppData.ExtensibleDataType appData = AppData.ExtensibleDataType.FromXml(xml);  
  11.     // Create and add an ExternData node.  
  12.     WebsiteData.Website websiteData = new WebsiteData.Website();  
  13.     websiteData.Url = "http://xml-fx.com";  
  14.     websiteData.Contact = "Joe Bloggs";  
  15.     websiteData.Email = "info@xml-fx.com";  
  16.     appData.ExternData = websiteData;  
  17.     xml = appData.Xml;  
  18.     // Serialize and write test.002.xml.  
  19.     WriteFile(Path.Combine(folderPath, "test.002.xml"), xml);  
  20.     // Read and de-serialize test.002.xml.  
  21.     xml = ReadFile(Path.Combine(folderPath, "test.002.xml"));  
  22.     appData = AppData.ExtensibleDataType.FromXml(xml);  
  23.     // Change some ExternData info.  
  24.     websiteData = appData.ExternData as WebsiteData.Website;  
  25.     if (websiteData != null)  
  26.     {  
  27.         websiteData.Contact = "John Thomas";  
  28.     }  
  29.     xml = appData.Xml;  
  30.     // Serialize and write test.003.xml.  
  31.     WriteFile(Path.Combine(folderPath, "test.003.xml"), xml);  
  32. }