Click here to Skip to main content
15,921,028 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,


I am using xml file and reading that xml file using dataset.readxml function where I am getting all table wise tag
but right now my problem is I want to iterate forloop to check first table/tag if that matched then again i want to get that table and again iterate and match the other value.
e.g. if xml contains tag name 'component' at 6th row of table list I want to get that and again iterate for other information. Now in component i want to check class with my input parameter value if match then i want to go further like that.



C#
for (int i = 0; i < CompXMLDataSet.Tables.Count; i++)
           {
               DataTable DT = CompXMLDataSet.Tables[i];
               string TagName = DT.TableName.ToString();
               //if (TagName == "COMPONENT")
               if (TagName == "COMPONENT")
               {
                   for (int j = 0; j < DT.Rows.Count; j++)
                   {
                       if (DT.Rows[j]["name"].ToString() == classname)
                       {
                           string Componentid = DT.Rows[j]["Component_id"].ToString();
                           for (int ii = 0; ii < CompXMLDataSet.Tables.Count; ii++)
                           {
                               DT = CompXMLDataSet.Tables[ii];
                               TagName = DT.TableName.ToString();
                               if (TagName == "VAR")
                               {
                                   DataRow[] dtrow = DT.Select("Component_id=" + Componentid);
                                   for (int k = 0; k < dtrow.Length; k++)
                                   {
                                       if (Convert.ToInt32(dtrow.ElementAt(k)["vid"]) == cid)
                                       {
                                           ParType = GetParType(dtrow.ElementAt(k)["type"].ToString());
                                           return ParType;
                                       }
                                   }
                               }// if loop for TagName=="VAR"
                           }
                       }// if loop to check class name
                   } // For loop
               } //if loop for TagName=="COMPONENT"
           }



here cid and classname are my parameter passed to this method which will change according.

I want to reduce the execution time.

Is there any easy way to reduce the time. can we write any linq query for above?

Thanks
sjs
Posted

1 solution

You can use Linq something like this

from e in xmlDoc.Descendents("components")
where e.Elements("name") == somevalue

...


Not complete but is should give you a start
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900