I'm trying to write an XML file. The first thing I want to do is create the
parent node for the document:

eleMenuItems = xmldoc.CreateElement("menuItems")
xmldoc.DocumentElement.PrependChild(eleMenuItems)

The second line above causes by try statement to exit and catches this
generic error:

'Object reference not set to an instance of an object'

I'm not sure where to do now to figure out the problem. Is there something I
am missing concept wise when creating the parent node?

-Darrel

Re: XML: Why can't I create a parent node for my document? by Richard

Richard
Sat Oct 16 17:26:51 CDT 2004

You need to insert it as the document element before you dereference the document element - i.e.

XmlNode n = d.CreateElement("Foo");
d.InsertAfter(n, null);

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

I'm trying to write an XML file. The first thing I want to do is create the
parent node for the document:

eleMenuItems = xmldoc.CreateElement("menuItems")
xmldoc.DocumentElement.PrependChild(eleMenuItems)

The second line above causes by try statement to exit and catches this
generic error:

'Object reference not set to an instance of an object'

I'm not sure where to do now to figure out the problem. Is there something I
am missing concept wise when creating the parent node?

-Darrel


Re: XML: Why can't I create a parent node for my document? by Darrel

Darrel
Sat Oct 16 17:59:33 CDT 2004

Thanks, Richard.

In the end, I scrapped this method and went with an XMLWriter one. Which I
got working.

Which raises the question, when should I use XMLWriters and when should I
use XMLDoc?

-Darrel

"Richard Blewett [DevelopMentor]" <richardb@develop.com> wrote in message
news:e0Pv888sEHA.2128@TK2MSFTNGP11.phx.gbl...
> You need to insert it as the document element before you dereference the
> document element - i.e.
>
> XmlNode n = d.CreateElement("Foo");
> d.InsertAfter(n, null);
>
> Regards
>
> Richard Blewett - DevelopMentor
> http://staff.develop.com/richardb/weblog
>
> I'm trying to write an XML file. The first thing I want to do is create
> the
> parent node for the document:
>
> eleMenuItems = xmldoc.CreateElement("menuItems")
> xmldoc.DocumentElement.PrependChild(eleMenuItems)
>
> The second line above causes by try statement to exit and catches this
> generic error:
>
> 'Object reference not set to an instance of an object'
>
> I'm not sure where to do now to figure out the problem. Is there something
> I
> am missing concept wise when creating the parent node?
>
> -Darrel
>