Solved

XML - Clone() & InsertAfter() doubles node?

Posted on 2004-04-23
8
362 Views
Last Modified: 2008-02-01
Hi,

Anyone have any idea why my code clones a node and then writes it into my document at the specified location twice? Does this sound familiar to anyone?

XmlNode newItem = tempRoot.ChildNodes[0].Clone();
tempRoot.InsertAfter(newItem, tempRoot.ChildNodes[navNum]);

I have really isolated this problem and feel very certain that the problem arises from how I am using InsertAfter.


0
Comment
Question by:coltrane2003
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 14

Expert Comment

by:AvonWyss
ID: 10904406
Well, is the node which you are cloning maybe already there where you insert the clone?
0
 
LVL 2

Author Comment

by:coltrane2003
ID: 10904640
Yes I am sure it is not already there.
0
 
LVL 14

Accepted Solution

by:
AvonWyss earned 50 total points
ID: 10904660
Well, your source code suggests otherwise! You're cloning one of tempRoot's childs, and add it as one of tempRoot's childs. Thats seems like inserting the clone just where the original node already was, doesn't it?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:coltrane2003
ID: 10904736
Yes I see your point, but I have taken this into account. I should have clarified this part. I was ending up with 3 nodes that look like that instead of two - if that makes any sense.

My plan was to clone the first node and then to modify some of its values rather than to build that same node from scratch. This was advantageous because there are some cases where I'm not sure what structure the node will have.

In any case it is now mysteriously working! I've been stuck for 2 hours and now I can't repro! Very annoying.

Thanks for having a look.  
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 10904758
You're welcome!

But frankly, I don't think a C grade was appropriate here; may I kindly ask you to read the EE guidelines on grading for the next time? Thank you, and have a nice weekend.
0
 
LVL 2

Author Comment

by:coltrane2003
ID: 10904834
OK I'm sorry. You didn't actually solve my specific problem and so I didn't know what to do. I just gave you a C without thinking about it too much. I hadn't read the grading policy.

After reflecting on the answer you gave, I see that it is the best possible answer that you could have given based on the information you had. I will request that a moderator change the grade.

Thanks again.
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 10904854
Since I saw in your profile that you are a newcomer here, I guessed that you may not yet know that policy so well. Don't worry about it, and welcome to EE!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
.NET 2008 VB and C# 6 47
tableview is not updating 1 27
Release Dynamically Allocated Memory in C# 3 45
how to remove duplicate code from my project 5 48
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question