Solved

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

Posted on 2004-04-23
8
356 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

13 Experts available now in Live!

Get 1:1 Help Now