TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
leogodin217
NA
2
0
Object reference not set to an instance of an object. on XmlDocument Object
Jan 1 2004 12:10 PM
Hi All, I'm using the XmlDocument object to create a new XML document from scratch. In my code I declare the document object at the beginning of the class: XmlDocument doc; then I initialize it in a Form_Load Event handler: doc = new XmlDocument(); doc.CreateXmlDeclaration("1.0", "ASCII", string.Empty); doc.NodeChanged += new XmlNodeChangedEventHandler(this.MyNodeChangedEvent); doc.NodeInserted += new XmlNodeChangedEventHandler(this.MyXmlNodeInsertedEventHandler); doc.NodeRemoved += new XmlNodeChangedEventHandler(this.MyXmlNodeRemovedEventHandler); // Create the root node rootNode = doc.CreateNode(XmlNodeType.Element, "STATUSREPORT", string.Empty); newLineNode = doc.CreateTextNode("\n"); However, when I try to add an element to this document before saving it I get the following error : "Object reference not set to an instance of an object." The code I use to write the element is: XmlNode myNode = doc.CreateNode(XmlNodeType.Element, txtElementName.Text, null); myNode.InnerText = txtElementValue.Text; rootNode.AppendChild(myNode); This works if I do a doc.Save first but I don't think forcing the application to actually save an xml file is the way to go here. does anyone know what I'm doing wrong? thanks in advance, Leo
Reply
Answers (
1
)
Egg like timer
Advisable or not: properties for structs