Results 1 to 17 of 17

Thread: Optimize my code, Please

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476

    Post Optimize my code, Please

    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

    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
    		}
    	}
    }
    And heres my xml Structure:

    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>
    Last edited by Sgt-Peppa; May 26th, 2003 at 03:01 AM.
    Keep Smiling - even if its hard
    Frankie Says Relax, wossname Says Yeah!
    wossname:--Currently I'm wearing a gimp suit and a parachute.
    C# - Base64 Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width