Not being tricky with XmlDocument

K

knocte

I am using the XmlDocument class to generate a XML document "on the
fly", I mean, build it in memory so as to extract its contents with the
property "OuterXml".

I know how to create elements and attributes inside these elements, and
text and more elements inside elements... ¡except the first element!
(the DocumentElement). How can I create it? Because I think I am now
using a very "tricky" method...:

using System.Xml;

(...)

XmlDocument miNuevoDocumentoXml = New XmlDocument();
miNuevoDocumentoXml.LoadXml("<ROOT />");

(...)


Is there any other way to create the primary element called ROOT?

Thanks in advance.

Regards,

Andrew
 
M

Mike Schilling

knocte said:
I am using the XmlDocument class to generate a XML document "on the fly", I
mean, build it in memory so as to extract its contents with the property
"OuterXml".

I know how to create elements and attributes inside these elements, and
text and more elements inside elements... ¡except the first element! (the
DocumentElement). How can I create it? Because I think I am now using a
very "tricky" method...:

using System.Xml;

(...)

XmlDocument miNuevoDocumentoXml = New XmlDocument();
miNuevoDocumentoXml.LoadXml("<ROOT />");

Try
miNuevoDocumentoXml .DocumentElement =
miNuevoDocumentoXml .CreateElement("ROOT");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top