"node.InsertAfter" method only inserts node on final call

Discussion in 'XML' started by chris yoker, Jan 28, 2005.

  1. chris yoker

    chris yoker Guest

    hiya,

    I succesfully return a "nodeList" thru the "xmlDoc.SelectNodes" method.
    This nodeList is taken from a repetitive, uniform xml doc.

    I can successfully append a child node at the correct position using the
    following code:

    <code>
    <!--Node inserted into corrrect position in nodeList(0)-->
    nodeList(0).InsertAfter(additionalNode, nodeList(0).ChildNodes(5))
    </code>

    however, as soon as I try to do the same with nodeList(1), then
    apparently the SAME code that previously inserted the node into
    nodeList(0) doesn't do its job.

    <code>
    <!--Node NOT inserted into nodeList(0)-->
    nodeList(0).InsertAfter(additionalNode, nodeList(0).ChildNodes(5))

    <!--Node inserted into corrrect position in nodeList(1)-->
    nodeList(1).InsertAfter(additionalNode, nodeList(1).ChildNodes(5))
    </code>


    Surely, If i am using the "InsertAfter" method, then the node should
    have been inserted BOTH times?

    As a test, I swapped my code round, and I can confirm that the node is
    ONLY inserted on the 2nd call.

    <code>
    <!--Node NOT inserted into nodeList(1)-->
    nodeList(1).InsertAfter(additionalNode, nodeList(1).ChildNodes(5))

    <!--Node inserted into corrrect position in nodeList(0)-->
    nodeList(0).InsertAfter(additionalNode, nodeList(0).ChildNodes(5))
    </code>

    Can someone comment?I have been spent a bit of time on this, and am no
    further forward.
    Even if i could get hold of some sample code in vb / c# that did this,
    then I'm sure I could take it from there ;-)

    ta,
    yogiberr

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    chris yoker, Jan 28, 2005
    #1
    1. Advertising

  2. /chris yoker/:

    > <code>
    > <!--Node NOT inserted into nodeList(0)-->
    > nodeList(0).InsertAfter(additionalNode, nodeList(0).ChildNodes(5))
    >
    > <!--Node inserted into corrrect position in nodeList(1)-->
    > nodeList(1).InsertAfter(additionalNode, nodeList(1).ChildNodes(5))
    > </code>
    >
    >
    > Surely, If i am using the "InsertAfter" method, then the node should
    > have been inserted BOTH times?
    >
    > As a test, I swapped my code round, and I can confirm that the node is
    > ONLY inserted on the 2nd call.
    >
    > <code>
    > <!--Node NOT inserted into nodeList(1)-->
    > nodeList(1).InsertAfter(additionalNode, nodeList(1).ChildNodes(5))
    >
    > <!--Node inserted into corrrect position in nodeList(0)-->
    > nodeList(0).InsertAfter(additionalNode, nodeList(0).ChildNodes(5))
    > </code>


    Surely it is inserted both times but it is getting removed prior
    inserting it the second time. There's no 'InsertArfter' method in
    the standard DOM interfaces but if you look at the
    'Node.appendChild' [1], 'Node.insertBefore' [2] and
    'Node.replaceChild' [3] documentation you would find:

    > If the 'newChild' is already in the tree, it is first removed.


    [1] http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-184E7107
    [2] http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-952280727
    [3] http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-785887307

    --
    Stanimir
    Stanimir Stamenkov, Jan 29, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,442
  2. Tobias Merler
    Replies:
    6
    Views:
    382
  3. JFCM
    Replies:
    4
    Views:
    5,732
  4. =?Utf-8?B?ZG1hbm5pb24=?=

    FormView for inserts only

    =?Utf-8?B?ZG1hbm5pb24=?=, Apr 18, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    375
    =?Utf-8?B?ZG1hbm5pb24=?=
    Apr 18, 2006
  5. Replies:
    5
    Views:
    510
    Chris Uppal
    Nov 17, 2006
Loading...

Share This Page