I'm porting a program I wrote on C# to Cocoa and I'm trying to figure out how to use XML to go online to my website, grab the file and parse it, then compare the version and pop a message box to ask if you want to open your browser to the update page.
Here's the code from C#:
public void CheckVersion()
{
Version newVersion = null;
string url = "";
string newfeatures = "";
try
{
string xmlURL = "http://myurl.com/version.xml";
XmlRead = new XmlTextReader(xmlURL);
XmlRead.MoveToContent();
string elementName = "";
if ((XmlRead.NodeType == XmlNodeType.Element) &&
(XmlRead.Name == "myProgram"))
{
while (XmlRead.Read())
{
if (XmlRead.NodeType == XmlNodeType.Element)
elementName = XmlRead.Name;
else
{
if ((XmlRead.NodeType == XmlNodeType.Text) &&
(XmlRead.HasValue))
{
switch (elementName)
{
case "version":
newVersion = new Version(XmlRead.Value);
break;
case "url":
url = XmlRead.Value;
break;
case "newfeatures":
newfeatures = XmlRead.Value;
break;
}
}
}
}
}
}
catch (Exception)
{
MessageBox.Show("Could not connect to update checking server.");
}
finally
{
if (XmlRead != null) XmlRead.Close();
}
Version curVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
if (curVersion.CompareTo(newVersion) < 0)
{
string title = "New Version Online";
string question = "Download new version? \nmyProgram Version: " + newVersion.ToString();
if (DialogResult.Yes ==
MessageBox.Show(this, question + "\n\n" + newfeatures, title,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question))
{
System.Diagnostics.Process.Start(url);
}
}
}
I'm pretty new to cocoa and most of that C# code was a snippet so any advice or help would be great.
Thanks