EDN Admin
Well-known member
let say i have the following xml file<br/>
<br/>
<pre class="prettyprint" style=" <Users>
<User>
<Name>David</Name>
<Date>9/30/2012 10:52:00 PM</Date>
</User>
<User>
<Name>David</Name>
<Date>9/30/2012 11:02:05 PM</Date>
</User>
<User>
<Name>David</Name>
<Date>9/30/2012 11:52:00 PM</Date>
</User>
<User>
<Name>Michelle</Name>
<Login>9/30/2012 11:02:13 PM</Date>
</User>
<User>
<Name>Michelle</Name>
<Login>9/30/2012 11:02:54 PM</LoginDate>
</User>
</Users>[/code]
will like to read the last date of David and put it on a string in my C# program, in this case it will be "9/30/2012 11:52:00 PM" I have the following code which is suppose to read the date of a particular User, but it is not working
<pre class="prettyprint" style=" public void readLastDate(string name)
{
string filePaths = "logins.xml";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filePaths);
xmlDoc.DocumentElement.SetAttribute("searching",name);
XmlNodeList tests = xmlDoc.SelectNodes("//Users[Name =/*/@searching]/User");
foreach (XmlNode test in tests)
{
string myDate = test.SelectSingleNode("LoginDate").InnerText;
InfoBox.Items.Add("Last Date:" + myDate);
} [/code]
<br/>
Also, how would i handle an error if i want to read a date of a user that is not in the xml file, for example if i want to search for Daniel in my current xml file<br/>
<br/>
View the full article
<br/>
<pre class="prettyprint" style=" <Users>
<User>
<Name>David</Name>
<Date>9/30/2012 10:52:00 PM</Date>
</User>
<User>
<Name>David</Name>
<Date>9/30/2012 11:02:05 PM</Date>
</User>
<User>
<Name>David</Name>
<Date>9/30/2012 11:52:00 PM</Date>
</User>
<User>
<Name>Michelle</Name>
<Login>9/30/2012 11:02:13 PM</Date>
</User>
<User>
<Name>Michelle</Name>
<Login>9/30/2012 11:02:54 PM</LoginDate>
</User>
</Users>[/code]
will like to read the last date of David and put it on a string in my C# program, in this case it will be "9/30/2012 11:52:00 PM" I have the following code which is suppose to read the date of a particular User, but it is not working
<pre class="prettyprint" style=" public void readLastDate(string name)
{
string filePaths = "logins.xml";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filePaths);
xmlDoc.DocumentElement.SetAttribute("searching",name);
XmlNodeList tests = xmlDoc.SelectNodes("//Users[Name =/*/@searching]/User");
foreach (XmlNode test in tests)
{
string myDate = test.SelectSingleNode("LoginDate").InnerText;
InfoBox.Items.Add("Last Date:" + myDate);
} [/code]
<br/>
Also, how would i handle an error if i want to read a date of a user that is not in the xml file, for example if i want to search for Daniel in my current xml file<br/>
<br/>
View the full article