Solved

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

Posted on 2004-04-23
8
358 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

914 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now