Skip to Content.
Sympa Menu

xom-interest - Re: [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: "Michael Kay" <mike AT saxonica.com>
  • To: "'mg4news'" <mg4news AT gmail.com>, <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] insertChild( element, index ) inserts at the wrong place?
  • Date: Sun, 3 Aug 2008 18:45:04 +0100

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





Archive powered by MHonArc 2.6.24.

Top of Page