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

C

chris yoker

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
 
S

Stanimir Stamenkov

/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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top