المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : C# -- Xml child node problem [modified]



C# Programming
12-11-2009, 06:42 AM
Hi guys...
I have an issue with my xml file... actually im developing a console application which inserts the data from an Xml file
into my database... This happens with
certain verifications done within the console application, like
checking whether the application id given by the user matches with the application id present in the xml file and also whether that application
has certain permissions, like certain applications hav certain
previleges, sumthing like dat...
Accordingly the insertion of datas into the database takes place... the code is as follows:


class Class1
{
public string app;
public void perform()
{
OdbcConnection con= new OdbcConnection();
ADIBCrypto.Encryption64 crpto = new ADIBCrypto.Encryption64();
try
{

string connString = crpto.GetCnnStr(ConfigurationSettings.AppSettings["appname"],ConfigurationSettings.AppSettings["dsnSybase"]);
con.ConnectionString = connString;
con.Open();
Console.WriteLine("Connection Opened Successfully");
Console.WriteLine("Enter the application");
app=Console.ReadLine();
XmlDataDocument doc = new XmlDataDocument();
doc.Load(ConfigurationSettings.AppSettings["app"]);
XmlNodeList nodes = doc.GetElementsByTagName("Row");
foreach(XmlNode node in nodes)
{
if(node.HasChildNodes && node.ChildNodes.Count > 0)
{
string a_ID = node.ChildNodes[0].InnerText;
string a_ApplicationDescription = node.ChildNodes[1].InnerText;
string a_Category = node.ChildNodes[2].InnerText;
string a_Business_Owner = node.ChildNodes[3].InnerText;
string a_CreatedID = node.ChildNodes[4].InnerText;
string a_CreatedTimeStamp = node.ChildNodes[5].InnerText;
string a_Status = node.ChildNodes[6].InnerText;
if(a_ID==app)
{
//OdbcCommand cmd = new OdbcCommand("insert into EACS_Application values('"+a_ID+"','"+a_ApplicationDescription+"','"+a_Category+"','"+a_Business_Owner+"','"+a_CreatedID+"',getDate(),'"+a_Status+"','','','','','','','')",con);
//cmd.ExecuteNonQuery();
Console.WriteLine("App Inserted");
}
}
}
XmlDataDocument doc1 = new XmlDataDocument();
doc1.Load(ConfigurationSettings.AppSettings["fun"]);
XmlNodeList nodes1 = doc1.GetElementsByTagName("Row");
foreach(XmlNode node1 in nodes1)
{
if(node1.HasChildNodes && node1.ChildNodes.Count > 0)
{
string f_ID = node1.ChildNodes[0].InnerText;
string f_FunctionDescription = node1.ChildNodes[1].InnerText;
string f_AppId = node1.ChildNodes[2].InnerText;
string f_FileName = node1.ChildNodes[3].InnerText;
if(f_AppId==app)
{
Console.WriteLine("fun--{0}",f_FileName);
XmlDataDocument doc2 = new XmlDataDocument();
doc2.Load(ConfigurationSettings.AppSettings["funfile"]+"\\"+f_FileName+".xml");
XmlNodeList nodes2 = doc2.GetElementsByTagName("Function");
foreach(XmlNode node2 in nodes2)
{
if(node2.HasChildNodes && node2.ChildNodes.Count > 0)
{
string ff_Id = node2.ChildNodes[0].InnerText;
string ff_FunctionDescription = node2.ChildNodes[1].InnerText;
string ff_Url = node2.ChildNodes[2].InnerText;
string ff_AppId = node2.ChildNodes[3].InnerText;
string ff_Type = node2.ChildNodes[4].InnerText;
string ff_MenuCommand = node2.ChildNodes[5].InnerText;
string ff_Status = node2.ChildNodes[6].InnerText;
Console.WriteLine("funfile--{0}",ff_Id);
//OdbcCommand cmd1 = new OdbcCommand("insert into EACS_Function values('"+ff_Id+"','"+ff_FunctionDescription+"','"+ff_Url+"','"+ff_AppId+"','"+ff_Type+"','"+ff_MenuCommand+"','"+ff_Status+"','','','')",con);
//cmd1.ExecuteNonQuery();
}

}
}
}
}
Console.WriteLine("Function Inserted");
XmlDataDocument doc3 = new XmlDataDocument();
doc3.Load(ConfigurationSettings.AppSettings["fungrp"]);
XmlNodeList nodes3 = doc3.GetElementsByTagName("Row");
foreach(XmlNode node3 in nodes3)
{
if(node3.HasChildNodes && node3.ChildNodes.Count > 0)
{
string fg_GroupId = node3.ChildNodes[0].InnerText;
string fg_AppId = node3.ChildNodes[1].InnerText;
string fg_FuncId = node3.ChildNodes[2].InnerText;
string fg_FileName = node3.ChildNodes[3].InnerText;
if(fg_AppId==app)
{
XmlDataDocument doc4 = new XmlDataDocument();
doc4.Load(ConfigurationSettings.AppSettings["fungrpfile"]+"\\"+fg_FileName+".xml");
XmlNodeList nodes4 = doc4.GetElementsByTagName("FunctionGroup");
foreach(XmlNode node4 in nodes4)
{
if(node4.HasChildNodes && node4.ChildNodes.Count > 0)
{
string fgf_GroupId = node4.ChildNodes[0].InnerText;
string fgf_AppId = node4.ChildNodes[1].InnerText;
string fgf_FuncId = node4.ChildNodes[2].InnerText;
string fgf_Status = node4.ChildNodes[3].InnerText;
Console.WriteLine("fungrp--{0}",fgf_FuncId);
//OdbcCommand cmd2 = new OdbcCommand("insert into EACS_FunctionGroup values('"+fgf_GroupId+"','"+fgf_AppId+"','"+fgf_FuncId+"','"+fgf_Status+"','')",con);
//cmd2.ExecuteNonQuery();
XmlDataDocument doc5 = new XmlDataDocument();
doc5.Load(ConfigurationSettings.AppSettings["grp"]);
XmlNodeList nodes5 = doc5.GetElementsByTagName("Row");
foreach(XmlNode node5 in nodes5)
{
if(node5.HasChildNodes && node5.ChildNodes.Count > 0)
{
string g_Id = node5.ChildNodes[0].InnerText;
string g_Description = node5.ChildNodes[1].InnerText;
string g_FileName = node5.ChildNodes[2].InnerText;
if(fgf_GroupId==g_Id)
{
XmlDataDocument doc6 = new XmlDataDocument();
doc6.Load(ConfigurationSettings.AppSettings["grpfile"]+"\\"+g_FileName+".xml");
XmlNodeList nodes6 = doc6.GetElementsByTagName("Group");
foreach(XmlNode node6 in nodes6)
{
if(node6.HasChildNodes && node6.ChildNodes.Count > 0)
{
string gf_Id = node6.ChildNodes[0].InnerText;
string gf_Description = node6.ChildNodes[1].InnerText;
string gf_Type = node6.ChildNodes[2].InnerText;
string gf_Level = node6.ChildNodes[3].InnerText;
int gf_DailyLimit = Convert.ToInt32(node6.ChildNodes[4].InnerText);
string gf_Status = node6.ChildNodes[5].InnerText;
Console.WriteLine("grp--{0}",gf_Id);
//OdbcCommand cmd3 = new OdbcCommand("insert into EACS_Group values('"+gf_Id+"','"+gf_Description+"','"+gf_Type+"','"+gf_Level+"',"+gf_DailyLimit+",'"+gf_Status+"','','','','')",con);
//cmd3.ExecuteNonQuery();
}
}
}
}
}
}
}
}
}
}
con.Close();
Console.WriteLine("Connection Closed");
Console.ReadLine();
}

catch(OdbcException)
{
Console.WriteLine("Record already exists");
Console.ReadLine();
}
}


The problem is that on loading the "doc3" the tags in the xml file are not in the same order.. The Xml file is as follows:



CAPRC
CAPRC02
cap63
FG_53


ICCBranch
ICC
00001
FG_54


ICCBranch
ICC
00002
FG_55


ICC
ICCCardCen
00003
FG_56



so u can see that the AppID and the GroupId tags are not in the right order.. in certain rows the tag-appid is in childnode[0]
and in certain rows the tag
is in Childnode[1]... so my check in the application is not
performed properly.. instead of childnode index number can i make it check with the name of the tag...
please guide i am 95% done with my application and at the final stage i found out this bug http://www.barakasoft.com/script/Forums/Images/smiley_WTF.gif http://www.barakasoft.com/script/Forums/Images/smiley_frown.gif ... please guide me with
any better ideas...
Thanxx in advance...
Regards,
Tash

modified on Thursday, December 10, 2009 3:44 AM