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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chris yoker

    #1

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

    hiya,

    I succesfully return a "nodeList" thru the "xmlDoc.SelectN odes" 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).Ins ertAfter(additi onalNode, nodeList(0).Chi ldNodes(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).Ins ertAfter(additi onalNode, nodeList(0).Chi ldNodes(5))

    <!--Node inserted into corrrect position in nodeList(1)-->
    nodeList(1).Ins ertAfter(additi onalNode, nodeList(1).Chi ldNodes(5))
    </code>


    Surely, If i am using the "InsertAfte r" 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).Ins ertAfter(additi onalNode, nodeList(1).Chi ldNodes(5))

    <!--Node inserted into corrrect position in nodeList(0)-->
    nodeList(0).Ins ertAfter(additi onalNode, nodeList(0).Chi ldNodes(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!
  • Stanimir Stamenkov

    #2
    Re: &quot;node.Inse rtAfter&quot; method only inserts node on final call

    /chris yoker/:
    [color=blue]
    > <code>
    > <!--Node NOT inserted into nodeList(0)-->
    > nodeList(0).Ins ertAfter(additi onalNode, nodeList(0).Chi ldNodes(5))
    >
    > <!--Node inserted into corrrect position in nodeList(1)-->
    > nodeList(1).Ins ertAfter(additi onalNode, nodeList(1).Chi ldNodes(5))
    > </code>
    >
    >
    > Surely, If i am using the "InsertAfte r" 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).Ins ertAfter(additi onalNode, nodeList(1).Chi ldNodes(5))
    >
    > <!--Node inserted into corrrect position in nodeList(0)-->
    > nodeList(0).Ins ertAfter(additi onalNode, nodeList(0).Chi ldNodes(5))
    > </code>[/color]

    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.appendChi ld' [1], 'Node.insertBef ore' [2] and
    'Node.replaceCh ild' [3] documentation you would find:
    [color=blue]
    > If the 'newChild' is already in the tree, it is first removed.[/color]

    [1] http://www.w3.org/TR/DOM-Level-2-Cor...ml#ID-184E7107
    [2] http://www.w3.org/TR/DOM-Level-2-Cor...l#ID-952280727
    [3] http://www.w3.org/TR/DOM-Level-2-Cor...l#ID-785887307

    --
    Stanimir

    Comment

    Working...