M
manmit.walia
Hello All and Thank You for your time,
I am stuck on this exception handleing error. The problem is that when
I run my application the application works perfect but sometimes, I get
this error. I do not know where it is causing it but my guess would be
something with the function below. Any help would be greatfull, as this
would be a learning experience for me.
For this example: swTitle.Text = "AutoCAD 2004"
After the user selects the product from a listbox, a datagrid is binded
to an arraylist which is field with all of the <EmployeeName>
associated with that product.
So I have split the EmployeeName up into four fields (FirstName, MI,
LastName, Email). and each field will be a column in the datagrid.
Function Task:
**********************
1) Read XML file
2) Use XPath to find a particular node
3) Query the node for fields and print out the fields in datagrid
XML File Example:
**********************
<EMPProductType>
<ProductType>AutoCAD 2004</ProductType>
<ManagerEMail>[email protected]</ManagerEMail>
<EmployeeName>Joe,,Alexander,[email protected]</EmployeeName>
<EmployeeName>Joe,,Allen,[email protected]</EmployeeName>
<EmployeeName>Harold,,Anderson,[email protected]</EmployeeName>
<EmployeeName>Kent,,Berner,[email protected]</EmployeeName>
<EmployeeName>Tommy,,Childers,[email protected]</EmployeeName>
</EMPProductType>
Function:
**********************
void GetUserList()
{
XmlDocument doc = new XmlDocument();
doc.Load("http://dpi948.delta.com/dtedmprod:/Field_Operations/ETAM/SFT/Software.xml");
//XmlNode sw;
XmlNodeList sw;
XmlNode root = doc.DocumentElement;
// SEARCH XML FILE
string t = "'" + swTitle.Text + "'";
sw=root.SelectNodes("//EMPProductType[ProductType=" + t + "
]/EmployeeName");
total = sw.Count;
// RETURN DATA FROM XPATH
if(sw != null)
{
for (int i=0; i < sw.Count; i++)
{
len = sw.InnerXml.Length;
ind = sw.InnerXml.IndexOf(',');
fn = sw.InnerXml.Substring(0, ind);
ind = ind + 1;
len = len - ind;
s1 = sw.InnerXml.Substring(ind,len);
ind = s1.IndexOf(',');
mi = s1.Substring(0, ind);
if(mi == "")
{
mi = "x";
}
ind = ind + 1;
len = len - ind;
s1 = s1.Substring(ind, len);
ind = s1.IndexOf(',');
ln = s1.Substring(0, ind);
ind = ind + 1;
len = len - ind;
ue = s1.Substring(ind, len);
ul.Add (new user(fn, mi, ln, ue));
temp = temp + " " + fn + " " + mi + " " + ln + " " + ue + "<br>";
}
usedCount.Text = total.ToString();
myDataGrid.DataSource=ul;
myDataGrid.DataBind();
}
}
I am stuck on this exception handleing error. The problem is that when
I run my application the application works perfect but sometimes, I get
this error. I do not know where it is causing it but my guess would be
something with the function below. Any help would be greatfull, as this
would be a learning experience for me.
For this example: swTitle.Text = "AutoCAD 2004"
After the user selects the product from a listbox, a datagrid is binded
to an arraylist which is field with all of the <EmployeeName>
associated with that product.
So I have split the EmployeeName up into four fields (FirstName, MI,
LastName, Email). and each field will be a column in the datagrid.
Function Task:
**********************
1) Read XML file
2) Use XPath to find a particular node
3) Query the node for fields and print out the fields in datagrid
XML File Example:
**********************
<EMPProductType>
<ProductType>AutoCAD 2004</ProductType>
<ManagerEMail>[email protected]</ManagerEMail>
<EmployeeName>Joe,,Alexander,[email protected]</EmployeeName>
<EmployeeName>Joe,,Allen,[email protected]</EmployeeName>
<EmployeeName>Harold,,Anderson,[email protected]</EmployeeName>
<EmployeeName>Kent,,Berner,[email protected]</EmployeeName>
<EmployeeName>Tommy,,Childers,[email protected]</EmployeeName>
</EMPProductType>
Function:
**********************
void GetUserList()
{
XmlDocument doc = new XmlDocument();
doc.Load("http://dpi948.delta.com/dtedmprod:/Field_Operations/ETAM/SFT/Software.xml");
//XmlNode sw;
XmlNodeList sw;
XmlNode root = doc.DocumentElement;
// SEARCH XML FILE
string t = "'" + swTitle.Text + "'";
sw=root.SelectNodes("//EMPProductType[ProductType=" + t + "
]/EmployeeName");
total = sw.Count;
// RETURN DATA FROM XPATH
if(sw != null)
{
for (int i=0; i < sw.Count; i++)
{
len = sw.InnerXml.Length;
ind = sw.InnerXml.IndexOf(',');
fn = sw.InnerXml.Substring(0, ind);
ind = ind + 1;
len = len - ind;
s1 = sw.InnerXml.Substring(ind,len);
ind = s1.IndexOf(',');
mi = s1.Substring(0, ind);
if(mi == "")
{
mi = "x";
}
ind = ind + 1;
len = len - ind;
s1 = s1.Substring(ind, len);
ind = s1.IndexOf(',');
ln = s1.Substring(0, ind);
ind = ind + 1;
len = len - ind;
ue = s1.Substring(ind, len);
ul.Add (new user(fn, mi, ln, ue));
temp = temp + " " + fn + " " + mi + " " + ln + " " + ue + "<br>";
}
usedCount.Text = total.ToString();
myDataGrid.DataSource=ul;
myDataGrid.DataBind();
}
}