Solved

ERror using xml AppendChild

Posted on 2014-10-09
3
176 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 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

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.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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 …
Starting up a Project

689 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