The clear there is correct... and not correct. That is, the idea is right, but the implementation is wrong.
You've actually got two hash tables there, one storing attribute names and values, and another storing that hash table in another hash table using an incrementing value (iindex) as the key.
I see what you're trying to do... you want to make sure you're only adding the attributes for that particular node into Proptablab so you clear Proplabval each time you go through, but what you may not have realized is that almost everything except simple value types (ie, int, float, double, etc...) is a reference type.
So you're throwing Proplabval into Proptablab, then clearing it right after, so you're going to have the empty hash table, which is what you're seeing. What you need to do is create a new hash table for the inner loop... I'll modify your code.
- // This code would have been wherever you defined these two HashTables
-
HashTable Proptablab = new HashTable();
- //HashTable Proplabval = new HashTable(); // Do this in the loop now
-
...
-
iindex = 0;
-
foreach (XmlNode Labelnodes1 in Labelnode)
-
{
-
HashTable Proplabval = new HashTable();
-
countlab = Labelnodes1.Attributes.Count;
-
for (int i = 0; i < countlab; i++)
-
{
-
String temp2 = Labelnodes1.Attributes[i].Name;
-
String temp1 = Labelnodes1.Attributes[i].InnerText;
-
Proplabval.Add(temp2, temp1);
-
}
-
-
Proptablab.Add(iindex, Proplabval);
-
//Proplabval.Clear(); //This can actually be removed
-
iindex++;
-
}
Give that a try :)