I'm a NEWB and I'm lost. I beg your patience.
I have a working application where I believe I am serializing (??) xml file data using the following code.
public static string elementUser(object sender)
{
XmlDocument xmldoc = new XmlDocument();
fileExistsRequest(xmldoc);
XmlNodeList nodelist = xmldoc.SelectNodes("//Name");
foreach (XmlNode xmlnode in nodelist)
{
if (xmlnode["User"] != null)
{
usertxt = xmlnode["User"].InnerText;
}
else
{
}
return usertxt;
}
return usertxt;
}
After calling this I load the contents of the xml element in a winForm for display to the user to manipulate. Other forms will call other elements. Ex Math.cs will call only <Start> <End> or <Ticks> for use in other dialogs.
The above was designed to work on one xml file with one entry (??) which looks like this
<?xml version="1.0" encoding="utf-8"?>
<SubmitTime12>
<Name Key="11/18/2014">
<User>fpytel</User>
<Date>11/18/2014</Date>
<JobNum>00000</JobNum>
<RevNum>CR8</RevNum>
<Task>why</Task>
<Start>00:00 AM</Start>
<End>8:00 AM</End>
<Ticks></Ticks>
<Explanation>Expletives Abound</Explanation>
</Name>
</SubmitTime12>
It occurred to me that I could use elementUser(object sender) to load other xml files with the same basic format, but with more entries. Really the only change would be that the <User> is not included in the Reportfpytel.xml file entries as the user is part of the file name. Ex:
...
<Name Key="11/14/2014 6:45:57 AM">
<Date>11/3/2014</Date>
<JobNum>00000</JobNum>
<RevNum>00000</RevNum>
<Task>Testing less</Task>
<Start>4:00 AM</Start>
<End>4:00 AM</End>
<TotalTime></TotalTime>
</Name>
<Name Key="11/14/2014 6:46:39 AM">
<Date>11/13/2014</Date>
<JobNum>26356</JobNum>
<RevNum>00000</RevNum>
<Task>Red Lines</Task>
<Start>2:00 AM</Start>
<End>2:00 AM</End>
<TotalTime></TotalTime>
</Name>
...
So in the first code above I replaced fileExistsRequest(xmldoc); with the following call by creating it in the elementUser(object sender); and refactoring it out of the code. This is what was supplied by VS2010.
public static void locateFolder(object sender, XmlDocument xmldoc)
{
string senderName = sender.ToString();
if (senderName == "Start")
{
}
else if (senderName.Contains("ApproveTime"))
{
fileExistsRequest(xmldoc);
}
else if (senderName.Contains("Report"))
{
fileExistsReport(xmldoc);
}
else if (senderName == "Math")
{
fileExistsReport(xmldoc);
}
}
This works without error but will not load the elements to the controls on the calling form. I stepped through every line from the time it is called (either onLoad or onShown) and it finds the folder, finds the file, finds the element, assigns the element to a string and gets ready to feed the string to the control on the calling form. When I take the final step to bring it to the form it clears the string to "" and shows the calling form with blank fields.
If I put a break in the locateFolder(object sender, XmlDocument xmldoc) function and try to step past this
string senderName = sender.ToString();
I get a NullReferenceException error with tips new keyword and checking if the object is null. That's the only error I can find that is giving me a hint. Almost like it's loading the strings into the controls and then emptying the contents again. What I don't understand is why it works just fine without the locateFolder() call and why no error is thrown when I do not place a break in the code to try to find the error. Like I said, I have made that call on the Shown event as well as the Load event.
Is there anyone that understands what's going on here. I really would like to reuse this code.
No comments:
Post a Comment