//Method return an XML
public Hashtable GetSimpleCollection()
{
Hashtable XMLmappingHash = new Hashtable();
////Test XML parser....
XmlTextReader testXMlReader = XMLparse();
//Load the Loop
while (!testXMlReader.EOF)
{
//Go to the name tag
testXMlReader.Read();
//if not start element exit while loop
//if (!testXMlReader.IsStartElement())
//{
// break; // TODO: might not be correct. Was : Exit While
//}
string nodetype = testXMlReader.Name;
string attributeValue = string.Empty;
if (nodetype == "excelcol")
{
while (testXMlReader.MoveToNextAttribute())
{
attributeValue = testXMlReader.Value;
}
XMLmappingHash.Add(testXMlReader.ReadElementString("excelcol"), attributeValue);
}
}
return XMLmappingHash;
}
// Another Mehtod return hashtable
public Hashtable GetCompositeHashtable()
{
string val =string.Empty;
StringBuilder sb;
Hashtable CompHashtable=new Hashtable();
XmlDocument XMLRead = new XmlDocument(); // Create instance of XmlDocument class
//XMLRead.Load(Server.MapPath("Page1.xml")); // Load Xml file
XMLRead.Load("D:\\Work\\GetExcelSheetNames\\XMLFile.xml");
XmlNodeList nodes = XMLRead.SelectNodes(@"excelMapping/tableName");
foreach (XmlNode node in nodes)
{
XmlNodeList nodes2list = node.ChildNodes;
for (int i = 0; i < nodes2list.Count; i++)
{
string key = "comp1" + i;
string Nodetype = nodes2list[i].Name;
if (Nodetype == "excelsComposite")
{
XmlNode CompositeNode = nodes2list.Item(i);
XmlNodeList CompNodeChild = CompositeNode.ChildNodes;
sb = new StringBuilder();
foreach (XmlNode CompChild in CompNodeChild)
{
if (CompChild.Attributes["operation"].Value == "Add")
{
foreach (XmlNode CompChildNodeValue in CompChild)
{
//sb = sb.Append("SUM");
sb = sb.Append(CompChildNodeValue.InnerText);
sb= sb.Append(",");
}
if (sb.Length!=0)
{
sb.Remove(sb.Length - 1, 1);
}
}
if (CompChild.Attributes["operation"].Value == "Divide")
{
sb = sb.Append(CompChild.InnerText);
//val = "(x1+x2)/x3";
}
//string ControlID = n2a.InnerText.Trim();
// string ControlType = n2a.Attributes["ControlType"].Value;
// string AccessMode = n2a.Attributes["AccessType"].Value;
// AddControl(ControlType, ControlID, AccessMode);
}
CompHashtable.Add(key, sb);
}
}
}
return CompHashtable;
}
////Method that merge two diffrent Hashtables
public Hashtable GetCompleteCollection()
{
string HashKey = string.Empty;
string HashValue = string.Empty;
Hashtable DatafieldHashmap = new Hashtable();
Hashtable CompHashMap = new Hashtable();
DatafieldHashmap = GetSimpleCollection();
CompHashMap = GetCompositeHashtable();
IDictionaryEnumerator Hashmap = CompHashMap.GetEnumerator();
while (Hashmap.MoveNext())
{
HashKey = Hashmap.Key.ToString();
HashValue = Hashmap.Value.ToString();
DatafieldHashmap.Add(HashKey,HashValue);
}
return DatafieldHashmap;
}
//// Call this on page load like this
Hashtable XMLCollectionreturn = new Hashtable();
XMLCollectionreturn = GetCompleteCollection();