Hey, i am pretty new to C# and wrote some code for work. Before turnimg that in could you please take a alook and make suggestions to optimize it. I am pretty sure that there are ways to make this code a lot better. Thanx in advance,
Stephan
And heres my xml Structure:Code:XmlDocument source = new XmlDocument(); //new Instance of xml-Document source.Load(@"C:\cvs\TeccomPOC\xml\regExp.xml"); // select the xml source XmlNode docElement = source.DocumentElement; // new Instance of Node bool found =false; // Variable to keep track if a regexpresion has been found bool goon = true; //Variable to break out of a foreach loop int count =0; // keeping track of the amount of loops int max = docElement.ChildNodes.Count; // count the childnodes while (goon ==true && count<=max) // do as long as goon is true and the count has not reached the amount of childnodes { foreach(XmlNode n2 in docElement.ChildNodes) //for every childnode in <doctypes> { if(n2.Name =="type") //if childnode is called type { foreach(XmlNode n3 in n2.ChildNodes) // for every childnode in <type> { if (count ==max) { header = "UNKNOWN"; } if (found == true) // has the regexpresion been found { header = n3.InnerText; // assign the name of the source to the header found = false; goon=false; break; } if(n3.Name == "regexpression") // if childnode is called regexpression { string tmp = n3.InnerText; // assign the tag-value to tmp if(rest.IndexOf(tmp) !=-1) //compare the tmp to the rest of the file { found =true; // if the regexp is found set found to true } } } count = count +1; // keeping track of the amounts of loops } } }
Code:<doctypes> <type> <regexpression>test::</regexpression> <name>test1</name> <containsbin>no</containsbin> </type> <type> <regexpression>testing::</regexpression> <name>test2</name> <containsbin>no</containsbin> </type> </doctypes>





Reply With Quote