odd order of things being returned - not sure why - help me debug?

Hi all.
Here's my problem - excuse me for asking odd but i don't know how else to explain it.

I have this method
public ArrayList getReportPageTitles() {
ArrayList coursePageTitles = new ArrayList();

XmlNodeList courseInfoFileNameNodes = this.SelectNodes("dts/course_info/FileSet/File");
foreach (XmlNode courseInfoFileNameNode in courseInfoFileNameNodes)
logger.Debug("test: " + courseInfoFileNameNode.Attributes["pageName"].Value);
return coursePageTitles;

however, that same xml pulls out earlier in a course list in the right order, which is
02_ ..
03_ ...

can anyone just point me in the right direction at least, cause i'm beyond stumped.

LVL 39
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:
Can you post a snippet of your XML that contains the nodes in question ?
blue-genieAuthor Commented:
i think the xml gets generated dynamically, there's no physical xml file, and i know we are using some xslt - i'll have a nosey round and see if I find anything.
blue-genieAuthor Commented:
i've just noticed the xml node structure is the wrong way round. so i'm guessing need to tackle where the xml gets written.
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Actually the foreach statement is not particularly picky about it's ordering, sometimes it comes out in the order you would expect, other times it doesn't.  I would suggest changing to a for(int intIdx;intIdx < blah;intIdx++) type loop instead.  I never use a foreach if the ordering is important, I reserve it for instances where I want to go through every object in the collection and the ordering is irrelevant.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Or instead of an arraylist you can use a queue which will return things FIFO and just enumerate through the queue.

Cynergy Software
blue-genieAuthor Commented:
i've discovered this method
protected ArrayList addFileNames(XmlNode item, ArrayList fileList) {
XmlNode resource = null;
if (item.Attributes["identifierref"] != null){
resource=this.ResourcesNode.SelectSingleNode("./default:resource[@identifier=\""+item.Attributes["identifierref"].Value+"\" and @adlcp:scormtype=\"sco\" and @href]" , this.nameSpaceManager);
if (resource!=null)
//Blank item header entry needed?
XmlNodeList subList = item.SelectNodes("./default:item", this.nameSpaceManager);
foreach (XmlNode subItem in subList)
this.addFileNames(subItem, fileList);
return fileList;

and I think it's this method that's putting things into fileList wrong.

Carl TawnSystems and Integration DeveloperCommented:
It looks like the addFileNames method is being called recursively, so it could very well be the cause of the items being out of order. You would need to step through it with the debugger to verify this.
blue-genieAuthor Commented:
ok, i take that back, it's doing right, back to the drawing board.
Have you tried sorting the arraylist

Return coursePageTitles.Sort();
blue-genieAuthor Commented:
what's sorting going to do? will it return the items alphabetically?
i've pinpointed the method that's mixing things up so i'm gonna have a nosey round there today and see what i come up with.
Yes, sorting will reutn items alphabetically
blue-genieAuthor Commented:
which i don't want.
okay, here's where i'm at.
System.Collections.Hashtable scoDetailsTable = courseManager.ScoDetails;
//i've checked the ScoDetails is a hashTable, and the items are in the right order
System.Collections.IDictionaryEnumerator enumerator = scoDetailsTable.GetEnumerator();

while (enumerator.MoveNext())

XmlNode fileNode = this.CreateNode(XmlNodeType.Element, "File", "");
fileNode.Attributes.Append(this.CreateAttribute("ident")).Value = enumerator.Key.ToString();
fileNode.Attributes.Append(this.CreateAttribute("pageName")).Value = enumerator.Value.ToString();
//this next line prints out now in the wrong order ......
System.Windows.Forms.MessageBox.Show("filenode: " +enumerator.Value.ToString());

please please please help!!!!
Pls post here the full xml (the correct order one) and I will try to reproduce/fix the problem
blue-genieAuthor Commented:
hi thanks, i've come to the conclusion that I can't use a hashtable so will be rewriting the code  to use an arraylist.
thanks for your efforts all.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.