Skip to Content.
Sympa Menu

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

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: mg4news <mg4news AT gmail.com>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] insertChild( element, index ) inserts at the wrong place?
  • Date: Sun, 03 Aug 2008 10:35:50 -0700

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





Archive powered by MHonArc 2.6.24.

Top of Page