• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

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)
{
coursePageTitles.Add(courseInfoFileNameNode.Attributes["pageName"].Value);
logger.Debug("test: " + courseInfoFileNameNode.Attributes["pageName"].Value);
}
return coursePageTitles;
}
02_Brand_Portfolio_Guidelines
assessment
03_Analysis
01_What_is_the_marketing_way

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

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

0
blue-genie
Asked:
blue-genie
  • 7
  • 3
  • 2
  • +2
4 Solutions
 
Carl TawnSystems and Integration DeveloperCommented:
Can you post a snippet of your XML that contains the nodes in question ?
0
 
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.
0
 
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LordWabbitCommented:
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.
0
 
CynergySoftwareCommented:
Or instead of an arraylist you can use a queue which will return things FIFO and just enumerate through the queue.

Cynergy Software
0
 
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)
{
fileList.Add(resource.Attributes["href"].Value);
}
}
else
{
//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.

0
 
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.
0
 
blue-genieAuthor Commented:
ok, i take that back, it's doing right, back to the drawing board.
0
 
gbzhhuCommented:
Have you tried sorting the arraylist

Return coursePageTitles.Sort();
0
 
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.
0
 
gbzhhuCommented:
Yes, sorting will reutn items alphabetically
0
 
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());
fileSetNode.AppendChild(fileNode);
}

please please please help!!!!
blu
0
 
gbzhhuCommented:
Pls post here the full xml (the correct order one) and I will try to reproduce/fix the problem
0
 
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.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 7
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now