Solved

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

Posted on 2004-04-23
8
360 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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