E
Elliot
I am writing a program to get the content of a xml file at a interval time.
However, label1.Text did not change. Can anyone find the problem for me?
Any idea would be appreciated.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
System.Timers.Timer mainxmltmr = new System.Timers.Timer(10000);
mainxmltmr.Elapsed += new
System.Timers.ElapsedEventHandler(mainxmltmr_Elapsed);
mainxmltmr.Start();
}
private void mainxmltmr_Elapsed(object sender,
System.Timers.ElapsedEventArgs e)
{
try
{
string strXmlFile = "http://localhost/xml.xml";
XmlDocument objXml = new XmlDocument();
objXml.Load(strXmlFile);
XmlElement objDocumentRoot = objXml.DocumentElement;
label1.Text = objDocumentRoot.GetAttribute("value");
}
catch (Exception){}
}
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<AF value="hi">
</AF>
However, label1.Text did not change. Can anyone find the problem for me?
Any idea would be appreciated.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
System.Timers.Timer mainxmltmr = new System.Timers.Timer(10000);
mainxmltmr.Elapsed += new
System.Timers.ElapsedEventHandler(mainxmltmr_Elapsed);
mainxmltmr.Start();
}
private void mainxmltmr_Elapsed(object sender,
System.Timers.ElapsedEventArgs e)
{
try
{
string strXmlFile = "http://localhost/xml.xml";
XmlDocument objXml = new XmlDocument();
objXml.Load(strXmlFile);
XmlElement objDocumentRoot = objXml.DocumentElement;
label1.Text = objDocumentRoot.GetAttribute("value");
}
catch (Exception){}
}
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<AF value="hi">
</AF>