Home All Groups Group Topic Archive Search About

Not being tricky with XmlDocument

Author
3 Apr 2005 10:45 PM
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

Author
3 Apr 2005 11:55 PM
Mike Schilling
Show quote Hide quote
"knocte" <knocte@NO-SPAM-PLEASE-gmail.com> wrote in message
news:d2prlu$2hr$1@nsnmpen3-gest.nuria.telefonica-data.net...
>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");
Are all your drivers up to date? click for free checkup

Author
6 Apr 2005 9:46 PM
knocte
Mike Schilling escribió:
Show quoteHide quote
> "knocte" <knocte@NO-SPAM-PLEASE-gmail.com> wrote in message
> news:d2prlu$2hr$1@nsnmpen3-gest.nuria.telefonica-data.net...
>
>>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");
>
>


Thanks for your answer, Mike, but that property is read-only.

Anyone knows another method?

Regards,

   knocte
Author
6 Apr 2005 11:03 PM
Mike Schilling
Show quote Hide quote
"knocte" <knocte@NO-SPAM-PLEASE-gmail.com> wrote in message
news:d31lcc$rsg$1@nsnmpen3-gest.nuria.telefonica-data.net...
> Mike Schilling escribió:
>> "knocte" <knocte@NO-SPAM-PLEASE-gmail.com> wrote in message
>> news:d2prlu$2hr$1@nsnmpen3-gest.nuria.telefonica-data.net...
>>
>>>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");
>>
>>
>
>
> Thanks for your answer, Mike, but that property is read-only.

So it is..

In that case, just do
    miNuevoDocumentoXml .AppendChild(miNuevoDocumentoXml
..CreateElement("ROOT"));

Bookmark and Share