Find the Error
This code was written by me, in a late night moment, when copy paste seems the best option
It started this way :
public string ImportFeed(string URL) { string ret = ""; XmlDocument xd = new XmlDocument(); xd.Load(URL); for(int i=0;i<xd.ChildNodes.Count;i++) { ret += xd.ChildNodes[i].Name; } return ret; }
So far , nothing special. Just open the url, read into an XML , return first nodes. Then I wanted more – next nodes. Nothing easier – why bother with recursion or proper variable names ? Just copy and paste :
public string ImportFeed(string URL) { string ret = ""; XmlDocument xd = new XmlDocument(); xd.Load(URL); for(int i=0;i<xd.ChildNodes.Count;i++) { ret += xd.ChildNodes[i].Name; for (int j = 0; i < xd.ChildNodes[i].ChildNodes.Count; j++) { ret += xd.ChildNodes[i].ChildNodes[j].Name; } } return ret; }
Could you spot the error ?
Hint : I have discovered after 10 seconds …but not looking at the code…
the pb is here:
for (int j = 0; i < xd.ChildNodes[i].ChildNodes.Count; j++)
it should be j < , not i <
right!
Took me 5 secs, reading your post. 😉
Come on, give us something tougher!
Wirklich Nice! i like it! Wo ist denn der Facebook-Like-Button 😉 Matthias
I will post ASAP.
Ei bine, cu rușine recunosc că nici după 30 sec nu m-am prins. M-am enervat și am derulat la comentarii :))
na ja…. such indexes i, j, l could be dangerous