?
Solved

ERror using xml AppendChild

Posted on 2014-10-09
3
Medium Priority
?
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
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…
Suggested Courses

771 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