When you get XML data with irregular structure; not naturally fitting a DataSet and you want an Object Model to easily work with the data. You can use the XML Schema Definition Tool (Xsd.exe) with the /classes option to generate C# or VB.Net classes from an XML file.
The XSD.exe lives in :
C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\xsd.exe
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\xsd.exe
You run xsd.exe from the Visual Studio Command Line.
-Start
-All Programs
-Visual Studio
-Tools
-Command Line
This is the command to view all the XSD command line parameters:
xsd /?
To convert an irregular XML file (XmlResponseObject.xml) into Classes:
xsd c:\Temp\XmlResponseObject.xml /classes /language:CS /out:c:\Temp\
This will generate a csharp file with classes that represent the XML. You may want to refeactor it out into separate class files being careful about duplicate classes in the single file that are disambiguate by namespace. Either way the classes wont be the nicest looking with all the xml attributes but the good part is you can bind to them via XML. This is an example where I retrive XML via a REST webservice, xmlResponseObject is the ObjectModel of classes that fits the XML.
public interface IYourWebService
{
XmlResponseObject GetData(int dataId);
}
public class YourWebService : IYourWebService
{
public XmlResponseObject GetData(int dataId)
{
XmlResponseObject xmlResponseObject = null;
var url = "http://SomeSite.com/Service/GetData/" + dataId;
try
{
var request = WebRequest.Create(url) as HttpWebRequest;
if (request != null)
{
request.AllowAutoRedirect = true;
request.KeepAlive = true;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322; InfoPath.2; .NET4.0C; .NET4.0E)";
request.Credentials = CredentialCache.DefaultNetworkCredentials;
request.CookieContainer = new CookieContainer();
var response = request.GetResponse() as HttpWebResponse;
if (request.HaveResponse && response != null)
{
var streamReader = new StreamReader(response.GetResponseStream());
var xmlSerializer = new XmlSerializer(typeof(XmlResponseObject));
xmlResponseObject = (XmlResponseObject)xmlSerializer.Deserialize(streamReader);
}
}
}
catch (Exception ex)
{
string debugInfo = "\nURL: " + url;
Console.Write(ex.Message + " " + debugInfo + " " + ex.StackTrace);
}
return xmlResponseObject;
}
}
Given you wish to only send and receive document changes you could modify the classes with IsDirty flags. I'm sure though once you have the classes to work with, it will be dead easy to detect diff's.