Click here to Skip to main content
15,885,917 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am using XMLtextreader I want to loop through about 16 times.
So the reader works for 16 times consuming much time How to reduce the above code


C#
int []c=new int[28];
                    for (int b = 0; b < diff.Count; b++)
                    {
                        using (XmlTextReader reader = new XmlTextReader(filename))
                        {
                            bool isInside = false;
                            double x1 = 0; double y1 = 0; double z1 = 0; double x2 = 0; double y2 = 0; double z2 = 0;
                            while (reader.Read())
                            {
                                reader.WhitespaceHandling = WhitespaceHandling.None;
                                
                                if (!isInside && reader.LocalName == "Child" && reader.GetAttribute("id") == diff[b].Key && reader.GetAttribute("type") == lstGivenString[0])
                                {
                                    isInside = true;
                                   c[0]++;
                                }
                                else if (!isInside && reader.LocalName == "Child" && reader.GetAttribute("id") == diff[b].Key && reader.GetAttribute("type") == lstGivenString[1])
                                {
                                    isInside = true;
                                    c[1]++;
                                }
                                else if (!isInside && reader.LocalName == "Child" && reader.GetAttribute("id") == diff[b].Key && reader.GetAttribute("type") == lstGivenString[2])
                                {
                                    isInside = true;
                                   c[2]++;
                                }
}
}
}
Posted
Comments
Er. Puneet Goel 9-Apr-14 5:50am    
try to create you function and best is to do your home work yourself. Be a good programmer.
KUMAR619 9-Apr-14 6:00am    
Please help me to create a function
lukeer 9-Apr-14 6:28am    
I suspect that it's slow to read the same file diff.Count times. Try to read it once and use the same instance of XmlTextReader in each iteration of the loop. Maybe that's faster.
Maciej Los 9-Apr-14 8:44am    
Please, be more specific and provide more details about your issue. We don't see you screen and we can't read in your mind! Posting the structure of XML might help.
saber rezaii magham 9-Apr-14 9:15am    
do you want to speedup data reading from hard disk?

1 solution

Replace isInside = true; by break;
All of your if statements test for !isInside first, hence I guess you actually want to leave the while clause after any of the conditions has become true.
 
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