Flash & XML help (maybe XPATH problem)

[FONT=Verdana]Hiya folks,[/FONT]

[FONT=Verdana]I am nearing the end of a project and just need to solve one part to complete it.[/FONT]

[FONT=Verdana]I have an XML file which contains lots of information abut all the various courses that my college offers. Each course has it’s own set of nodes and the main node for each course contains all the attributes used for things like title, search keywords, image, background colours etc etc.[/FONT]


<course id="1" area="A Levels" bgcolor="E8E3BD" bgcolor2="ABAC39" code="Various" image="images/1.jpg" keywords="as, a2, a levels, a-levels, maths, science, social science, humanities, art and design, art, design, business" length="One/Two Years" level="3" location="Various Sites" name="AS and A2 levels" textcolor="FFFFFF" textcolor2="ABAC39">
<span class="subtitle">What&#8217;s it all about?</span>
A levels are normally a two year programme. In the first year you study AS subjects and when you have completed these, you move onto A2 subjects to achieve a full A level at the end of the second year.
<span class="subtitle">What does it involve?</span> 
We have re-designed our full-time A level programme to support and enhance your career aspirations. We offer A level pathways in Science, Social Science, Humanities, Art and Design and Business. These provide packages of related subjects that link to broader degree and career routes.

[COLOR=black][FONT=Verdana]I am using XPATH to loop through the XML and pull out all the courses that have a match in the keywords attribute to what the user enters in search field. I then display the results in a DataGrid component and when the user clicks on the result they want, I then call up a function that loads in all the correct course information.[/FONT][/COLOR]


// selects the nodes using &#8216;contains&#8217; function of XPath
var query:String = "//course[contains(@keywords, "+"'"+term+"'"+")]";
myResults = XPath.selectNodes(myDoc, query);
// Converts myResults array of xml nodes to regular array 
myDataSet = new Array();
for (var i = 0; i<myResults.length; i++) {
var name = XPath.selectNodes(myResults*, "//@name");
var id = XPath.selectNodes(myResults*, "//@id");
myDataSet.push({Name:name, ID:id});
//sends resulting array to result datagrid
this.dgSearchResults.dataProvider = myDataSet;

[COLOR=black][FONT=Verdana]Now the trouble I am having is that what is getting stored in the myDataSet array and thus passed to the loadScreen function is not:[/FONT][/COLOR]


[COLOR=black][FONT=Verdana]AS and A2 levels, 1[/FONT][/COLOR]



[COLOR=black][FONT=Verdana]Name=”AS and A2 levels”, ID=”1”[/FONT][/COLOR]

[COLOR=black][FONT=Verdana]So the DataGrid ends up showing the results as:[/FONT][/COLOR]


[COLOR=black][FONT=Verdana]Name=”AS and A2 levels”[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]Name=”Foundation Art & Design”[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]Name=”Foundation Fashion Design”[/FONT][/COLOR]


[COLOR=black][FONT=Verdana]Etc etc, and the value passed over to the loadScreen function with this bit of code:[/FONT][/COLOR]

var dgListener:Object = new Object();
dgListener.change = function(evt_obj:Object) {

[COLOR=black][FONT=Verdana]Is always something like ID=”1”, whereas I need it to simply be a numeric value like 1, 2, 78 etc.[/FONT][/COLOR]

[COLOR=black][FONT=Verdana]I have tried creating a function to convert the values to what I need using toString() & substring() functions to strip off what I don’t want (i.e the name=” and the trailing “)[/FONT][/COLOR]

// attempt to strip off name=&#8221; bit
var csname2 = myDatSet[0].csname.toString().substring(6,0);

[COLOR=black][FONT=Verdana]but it doesn’t work and csname2 is always undefined.[/FONT][/COLOR]

[COLOR=black][FONT=Verdana]I also in another project (http://me.snickers.com) remember having to store the values using something like:[/FONT][/COLOR]


_global.navData.push({link:linkname_array*.firstChild.nodeValue, file:linkfile_array*.firstChild.nodeValue});


[COLOR=black][FONT=Verdana]So that it stored the actual node value rather than the node & value together by pushing the value into the array object by referencing the nodeValue specifically…[/FONT][/COLOR]

[COLOR=black][FONT=Verdana]I know I am using attributes here instead of nodes, and if I change my XML to use nodes for the ‘keywords’ and ‘ID’ rather than attributes, it works, but as there are over 200 courses, I really don’t want to go back to a more primitive and messy XML structure and can’t see that it isn’t possible to do it with attributes instead (plus having to change 200 courses back into nodes etc would take far to much time).[/FONT][/COLOR]

[COLOR=black][FONT=Verdana]So can ANYONE please help me find a solution? I just need to know how to either store just the attribute value in my myDataSet array, OR, how to strip off all the un-needed bits (i.e. ID=” & the trailing “) before I pass the data to the loadScreen function and the results DataGrid.[/FONT][/COLOR]

[COLOR=black][FONT=Verdana]Any help would be really really appreciated and I can help by showing more files, code snippets etc if needed.[/FONT][/COLOR]

[COLOR=black][FONT=Verdana]Hope to hear from someone soon……[/FONT][/COLOR]