[XOM-interest] insertChild( element, index ) inserts at the wrong place?

Michael Kay mike at saxonica.com
Sun Aug 3 13:45:04 EDT 2008


Perhaps the parent element has some whitespace text nodes which you aren't
accounting for.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: xom-interest-bounces at lists.ibiblio.org 
> [mailto:xom-interest-bounces at lists.ibiblio.org] On Behalf Of mg4news
> Sent: 03 August 2008 18:36
> To: xom-interest at lists.ibiblio.org
> Subject: [XOM-interest] insertChild( element,index ) inserts 
> at the wrong place?
> 
> 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
> 
> _______________________________________________
> XOM-interest mailing list
> XOM-interest at lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/xom-interest



More information about the XOM-interest mailing list