public static bool WriteToXml(object inputDataset, string xmlFilePath)
 {
     try
     {
         // Check if file exists
         if (File.Exists(xmlFilePath))
         {
             Console.WriteLine("File already exists.");
             return(false);
         }
         // Create new file.
         IFile xmlFile = new FileStreamClass();
         xmlFile.Open(xmlFilePath, esriFilePermission.esriReadWrite);
         // See if the input dataset can be Xml serialized.
         IXMLSerialize mySerializeData = (IXMLSerialize)inputDataset;
         // Create new XmlWriter object.
         IXMLWriter myXmlWriter = new XMLWriterClass();
         myXmlWriter.WriteTo((IStream)xmlFile);
         myXmlWriter.WriteXMLDeclaration();
         IXMLSerializer myXmlSerializer = new XMLSerializerClass();
         // Write to XML File
         myXmlSerializer.WriteObject(myXmlWriter, null, null, null, null, mySerializeData);
         Console.WriteLine("Success.");
         return(true);
     }
     catch (Exception exc)
     {
         Console.WriteLine("Exception caught in WriteToXml: " + exc.Message);
         Console.WriteLine("Failed.");
         return(false);
     }
 }
 public static object ReadFromXml(string xmlFilePath)
 {
     try
     {
         IFile inputXmlFile = new FileStreamClass();
         inputXmlFile.Open(xmlFilePath, esriFilePermission.esriReadWrite);
         IXMLReader myXmlReader = new XMLReaderClass();
         myXmlReader.ReadFrom((IStream)inputXmlFile);
         IXMLSerializer myInputXmlSerializer = new XMLSerializerClass();
         object         myFunctionObject     = myInputXmlSerializer.ReadObject(myXmlReader, null, null);
         return(myFunctionObject);
     }
     catch (Exception exc)
     {
         Console.WriteLine("Exception caught in ReadFromXml: " + exc.Message);
         return(null);
     }
 }
 public static object ReadFromXml(string xmlFilePath)
 {
     try
     {
         IFile inputXmlFile = new FileStreamClass();
         inputXmlFile.Open(xmlFilePath, esriFilePermission.esriReadWrite);
         IXMLReader myXmlReader = new XMLReaderClass();
         myXmlReader.ReadFrom((IStream)inputXmlFile);
         IXMLSerializer myInputXmlSerializer = new XMLSerializerClass();
         object myFunctionObject = myInputXmlSerializer.ReadObject(myXmlReader, null, null);
         return myFunctionObject;
     }
     catch (Exception exc)
     {
         Console.WriteLine("Exception caught in ReadFromXml: " + exc.Message);
         return null;
     }
 }
 public static bool WriteToXml(object inputDataset, string xmlFilePath)
 {
     try
     {
         // Check if file exists
         if (File.Exists(xmlFilePath))
         {
             Console.WriteLine("File already exists.");
             return false;
         }
         // Create new file.
         IFile xmlFile = new FileStreamClass();
         xmlFile.Open(xmlFilePath, esriFilePermission.esriReadWrite);
         // See if the input dataset can be Xml serialized.
         IXMLSerialize mySerializeData = (IXMLSerialize)inputDataset;
         // Create new XmlWriter object.
         IXMLWriter myXmlWriter = new XMLWriterClass();
         myXmlWriter.WriteTo((IStream)xmlFile);
         myXmlWriter.WriteXMLDeclaration();
         IXMLSerializer myXmlSerializer = new XMLSerializerClass();
         // Write to XML File
         myXmlSerializer.WriteObject(myXmlWriter, null, null, null, null, mySerializeData);
         Console.WriteLine("Success.");
         return true;
     }
     catch (Exception exc)
     {
         Console.WriteLine("Exception caught in WriteToXml: " + exc.Message);
         Console.WriteLine("Failed.");
         return false;
     }
 }