Solved

ERror using xml AppendChild

Posted on 2014-10-09
3
169 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
ID: 40371955
Try changing line 4 to:
errDoc.DocumentElement.AppendChild(element)

Open in new window

0
 

Author Comment

by:ToolTimeGang
ID: 40372879
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
ID: 40372959
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

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

Suggested Solutions

Title # Comments Views Activity
topping1 challenge 7 73
tvirtualstringtree freeze when load too manny images 10 52
Java Loop 6 49
program a usb light to turn on when needed 6 49
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article will show, step by step, how to integrate R code into a R Sweave document
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

895 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