473,320 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

XML to ArrayCollection, sort and then convert to XML again

16
Hi everyone,

Please tell me what I am doing wrong:

I have an xml data coming to my Air application that looks something like this:
Expand|Select|Wrap|Line Numbers
  1. <project name="Sales Demos" path="/Company Home/Client Spaces/Sales Demos" type="{http://www.myCo.org/model/content/1.0}folder" id="71f36dcd-b59b-11dd-8205-5992b4466fe5" modified="Nov 18, 2008 3:51:20 PM" size="" icon32="/images/icons/default.gif" viewurl=""/>
  2. <project name="Something else" ...
  3. etc...
  4. />
  5.  
I want to place the XML into an ArrayCollection, so that I can sort it by the values referenced in the "name" attribute.

Expand|Select|Wrap|Line Numbers
  1.             import mx.collections.Sort;
  2.             import mx.collections.SortField;
  3.             import mx.collections.ArrayCollection;
  4.  
  5.                 var arrColl:ArrayCollection = new ArrayCollection;
  6.                 for each(var s:XML in tree.data.children())
  7.                 {
  8.                       arrColl.addItem(s);
  9.                 }
  10.  
  11.  
  12.                 /* Create the SortField object for the "data" field in the ArrayCollection object, and make sure we do a numeric sort. */
  13.                 var dataSortField:SortField = new SortField();
  14.                 dataSortField.name = "name";
  15.                 dataSortField.caseInsensitive = true;
  16.  
  17.                 /* Create the Sort object and add the SortField object created earlier to the array of fields to sort on. */
  18.                 var numericDataSort:Sort = new Sort();
  19.                 numericDataSort.fields = [dataSortField];
  20.  
  21.                 /* Set the ArrayCollection object's sort property to our custom sort, and refresh the ArrayCollection. */
  22.                 arrColl.sort = numericDataSort;
  23.                 arrColl.refresh();
  24.                 var someArrColToString:String = "<xml>";
  25.                 for each(var XMLNodeObj:Object in arrColl)
  26.                 {
  27.                      someArrColToString += "<project name='" + XMLNodeObj.name +
  28.                       "' path='" + XMLNodeObj.path + "' type='" +XMLNodeObj.type + 
  29.                       "' id='" + XMLNodeObj.id +"' modified='" +XMLNodeObj.modified +
  30.                       "' size='" + XMLNodeObj.size +"' icon32='" +XMLNodeObj.icon32 +
  31.                       "' viewurl='" + XMLNodeObj.viewurl +
  32.                       "' />";
  33.                     }
  34.                 someArrColToString += "</xml>";
  35.  
  36.                 var someStringToXml:XML = new XML(someArrColToString);
  37.                 trace("tree.data.children() "+tree.data.children()+" someArrColToString "+someArrColToString);
  38.  
I do a trace at the end to see what I've created and the tree.data.children() has the original xml in it's original order, but this is what I get back with the trace of var someArrColToString:

Expand|Select|Wrap|Line Numbers
  1. <xml><project name='' path='' type='' id='' modified='' size='' icon32='' viewurl='' /><project name='' path='' type='' id='' modified='' size='' icon32='' viewurl='' /><project name='' path='' type='' id='' modified='' size='' icon32='' viewurl='' /><project name='' path='' type='' id='' modified='' size='' icon32='' viewurl='' /><project name='' path='' type='' id='' modified='' size='' icon32='' viewurl='' /><project name='' path='' type='' id='' modified='' size='' icon32='' viewurl='' /><project name='' path='' type='' id='' modified='' size='' icon32='' viewurl='' /><project name='' path='' type='' id='' modified='' size='' icon32='' viewurl='' /><project name='' path='' type='' id='' modified='' size='' icon32='' viewurl='' /><project name='' path='' type='' id='' modified='' size='' icon32='' viewurl='' /><project name='' path='' type='' id='' modified='' size='' icon32='' viewurl='' /><project name='' path='' type='' id='' modified='' size='' icon32='' viewurl='' /><project name='' path='' type='' id='' modified='' size='' icon32='' viewurl='' /></xml>
  2.  
Which is showing me the correct amount of project tags but the attributes are not being filled.

Do I have to do something like XMLNodeObj.attribute.name?

What am I doing wrong?

Thanx n advance,
me
Jan 8 '09 #1
0 5726

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Colin Steadman | last post by:
I'm a stupid ASP programmer and I dont do Javascript (except for very simple tasks anyway), and I'm in a bit of a predicament. I've used a javascript table sorting script from here: ...
4
by: Bruce Pullum | last post by:
I have a datagrid that I am using a DataView with. All works great for the sorting of the columns. However, after I sort the column, and then try and select a data row to edit, the row selected...
2
by: Max Harvey | last post by:
Hi all, I have a form which is based on a table. The table (table1) has fields like Surname, Firstname, etc. I want to have the form sort by Surname, and then Firstname. I put the Orderby...
4
by: yer darn tootin | last post by:
Does anyone know the sort expression for a column that's data has been returned in the format, eg '07 Jul 05'?? The sort expression {..:"dd mmm yy"} doesn't work ( if the column was returned as...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
17
by: rhitz1218 | last post by:
Hi, I'm trying to create a function that will sort a number's digits from highest to lowest. For example 1000 - will become 0001 or 1234 to 4321
6
by: Nick Valeontis | last post by:
I know how to use Icomparable. However, I can't figure out how to sort a generic linked list? (without writing the algorithm) Lets say I have something like this: class...
0
by: JosAH | last post by:
Greetings, I was asked to write a Tip Of the Week; so here goes: a lot of topics are started here in this forum (and a lot of other forums too) mentioning a problem about sorting data. ...
9
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a generic list that is populated with a structure. I would like to be able to sort on values in the structure. I have public struct mergoutstruct { public Int32 projectnumber; public...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.