tags:

views:

463

answers:

2

Hi,

I have a trouble on appending new node to xmldocument (created in the memory). I have select the root node with the XmlDocument.SelectSingleNode() method, it work sometimes and in the other time it will give me "System.InvalidOperationException: This document already has a 'DocumentElement' node." error. More information, this xml document is multi level xml document.

By the way, when i try it with unit test it work fine (always), when i implement it in ASP.NET 3.5, it become weird, work sometimes and fail sometimes. Any idea, why this can help? All advise and suggestion are welcome.

Thanks.

A: 

You can select the root node of the XmlDocument using the Property "DocumentElement". Or i think you can use the Property "FirstChild" (untested).

System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
XmlElement rootNode = doc.DocumentElement;
Jehof
Hi, thanks for the reply. It can get the root node, but still throw "System.InvalidOperationException: This document already has a 'DocumentElement' node.". Funny thinks is it work sometime and sometime not.
Daniel Mahadi
A: 

Hi i tried to write the xml, with third party xmlhelper class. but it is not supported anymore. hope microsoft fix the xmldocument problem

Daniel Mahadi