draghuna
February 22nd, 2006, 12:22 PM
the code given below throws me a NULReferenceException error, can someone help me on this. The variable cFile is assigned from outside. I can see the list thats been accessed from the xml file but for some reason when I try to assign the productNode.Name it throws the error. Any Help is certainly appreciated. Thanks
CODE:
public class Product
{
public string Name;
public string abbrion;
}
public class Config
{
public string cFile;
public Product[] getProducts()
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load(cFile);
XmlNodeList pnode = xdoc.GetElementsByTagName("Prod");
Product [] productNode = new Product [pnode.Count];
for(int i=0; i < pnode.Count; i++)
{
productNode[i].Name = pnode[i].Attributes["ID"].Value.ToString();
productNode[i].abbr = pnode[i].Attributes["Description"].Value.ToString();
}
return productNode;
}
DD
CODE:
public class Product
{
public string Name;
public string abbrion;
}
public class Config
{
public string cFile;
public Product[] getProducts()
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load(cFile);
XmlNodeList pnode = xdoc.GetElementsByTagName("Prod");
Product [] productNode = new Product [pnode.Count];
for(int i=0; i < pnode.Count; i++)
{
productNode[i].Name = pnode[i].Attributes["ID"].Value.ToString();
productNode[i].abbr = pnode[i].Attributes["Description"].Value.ToString();
}
return productNode;
}
DD