[XOM-interest] insertChild( element, index ) inserts at the wrong place?
mg4news
mg4news at gmail.com
Sun Aug 3 13:35:50 EDT 2008
I have been using XOM to keep an alphabetically orderd list of users. If
I create a new element and append it it goes to the end of the list
(i.e. last element in the childs list), and works correctly, i.e.
something like
- xmlUserList.appendChild( newUserElement( "name" ) ); //
xmlUserList is the base element
If I use the insertChild call it seems to add elements in the wrong
place. For example if I start with a list of 3 users in the correct
order as follows:
- A (index 0), F (index 1), H (index 2)
I then try to insert users 'G' then'B', i.e.
- xmlUserList.insertChild( newUserElement( "G" ), 2 );
- xmlUserList.insertChild( newUserElement( "B" ), 1 );
I then get the following order of elements
- B (index 0), A (index 1), G (index 2), F (index 3), H (index 4)
If I do in in reverse, i.e. insert 'B' then 'G' , i.e.
- xmlUserList.insertChild( newUserElement( "B" ), 1 );
- xmlUserList.insertChild( newUserElement( "G" ), 3 );
I then get same following order of elements
- B (index 0), A (index 1), G (index 2), F (index 3), H (index 4)
I am pretty sure I must be doing something basic/stupid? Any ideas?
Thanks
MG
More information about the XOM-interest
mailing list