Solved

ERror using xml AppendChild

Posted on 2014-10-09
3
166 Views
Last Modified: 2014-10-15
I am getting "The current node cannot contain other nodes." on the AppendChild.
What am I doing wrong?  MainDoc contains valid xml.  I am just trying to add an error message at the end of it.
element = errDoc.CreateElement("myError")
element.InnerXml = "<ErrorMsg>" & Msg & "</ErrorMsg>" & _
                   "<Exception>" & exception & "</Exception>"
errDoc.AppendChild(element)
MainDoc = errDoc.OuterXml

Open in new window

0
Comment
Question by:ToolTimeGang
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
Comment Utility
Try changing line 4 to:
errDoc.DocumentElement.AppendChild(element)

Open in new window

0
 

Author Comment

by:ToolTimeGang
Comment Utility
Robert....it worked like a charm!  Thank you!  
This code has been recompiled from .NET 1.1 to .NET 4.5.
So I guess I can expect deprecated things like this as I continue my journey through these recompiles ey?
0
 
LVL 35

Expert Comment

by:Robert Schutt
Comment Utility
I'm not really sure, for your sake I hope not! To be honest I wasn't aware this has ever been possible (in this situation), thought I recognized a mistake I have made myself as far back as VB6. I guess it depends more on the object used than the specific language though. If it has been possible then I would say it was added in spite of the standard. Adding a second root element to the document should not be possible. Within its document element however not a problem.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

762 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

12 Experts available now in Live!

Get 1:1 Help Now