using System; using System.Collections; using System.Xml.Serialization; using System.Xml; using System.Text; using System.IO; namespace serializablexml { [Serializable] public class company { [SoapAttribute(AttributeName = "company")] public string companyname; [SoapElement(ElementName = "Corporate Office")] public string corporate_office; [SoapIgnore] public string comID; public override string ToString() { string send; send = "\n Comapany name" + this.companyname; send += "\n Corporate Office" + this.corporate_office; send += "\n Comapny ID:" + this.comID; return send; } public static void Main() { try { string filename = "D:\\company.soap"; XmlTypeMapping mymapping = (new SoapReflectionImporter().ImportTypeMapping(typeof(company))); XmlSerializer serializer = new XmlSerializer(mymapping); company mycompany = new company(); mycompany.companyname = "AC.ltd"; mycompany.comID = "124543"; mycompany.corporate_office = "Delhi"; XmlTextWriter writer = new XmlTextWriter(filename, Encoding.ASCII); writer.Formatting = Formatting.Indented; writer.WriteStartElement("Ccompany Info"); serializer.Serialize(writer, mycompany); writer.WriteEndElement(); writer.Close(); XmlTextReader reader = new XmlTextReader(filename); reader.ReadStartElement("Company Info"); mycompany=(company)serializer.Deserialize(reader); reader.ReadEndElement(); reader.Close(); } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); Console.WriteLine("========================================================="); Console.WriteLine(ex.Data); Console.WriteLine("========================================================="); Console.WriteLine(ex.Source); Console.WriteLine("=========================================================="); Console.WriteLine(ex.TargetSite); Console.WriteLine("========================================================="); Console.WriteLine(ex.StackTrace); Console.ReadLine(); } catch (XmlException ex) { Console.WriteLine(ex.Message); Console.WriteLine("========================================================="); Console.WriteLine(ex.Data); Console.WriteLine("========================================================="); Console.WriteLine(ex.Source); Console.WriteLine("=========================================================="); Console.WriteLine(ex.TargetSite); Console.WriteLine("========================================================="); Console.WriteLine(ex.StackTrace); Console.WriteLine("=========================================================="); Console.WriteLine(ex.LineNumber); Console.WriteLine("==========================================================="); Console.WriteLine(ex.LinePosition); Console.ReadLine(); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)