tags:

views:

155

answers:

1

Hello, this is in reference to a question asked earlier. Here is the complete code and it's giving me an error:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Xml;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;

namespace LoadXMLtreeDisplay
{
    public partial class TreeDisplay : Form
    {
        public string Filename
        {
            get { return filename; }
        }
        protected string filename;
        public TreeDisplay()
        {
            InitializeComponent();
            this.Text = "Tree View of XML File";//Form Title.
        }
       private void treeDocLoadMethod(string nameofFile)
        {
                XmlDocument xdoc = new XmlDocument();
                xdoc.Load(nameofFile);
                this.treeView1.Nodes.Clear();
                this.treeView1.Nodes.Add(new TreeNode(xdoc.DocumentElement.Name));
                TreeNode tNodeObj = new TreeNode();
                tNodeObj = this.treeView1.Nodes[0];
                XmlNode xNode = xdoc.DocumentElement;
                AddingNodesToTree(tNodeObj, xNode);
                treeView1.Nodes[0].Expand();
                treeView1.CollapseAll();
        }//treeDocLoadMethod

        private void AddingNodesToTree(refXmlNode xnode,TreeNode tnode)
        {

            TreeNode subNode = tnode.Add(xnode.Name);
            subNode.Tag = xnode;
            foreach (XmlNode subElement in xnode.ChildNodes)
            {
                AddingNodesToTree(ref subElement, ref subNode);
            }       

        } 
        private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
        { listBox1.Items.Clear();
            TreeNode currentNode = e.Node;
            XmlElement currentElement = (XmlElement)currentNode.Tag;
            XmlAttributeCollection attCol = currentElement.Attributes;
            foreach (XmlAttribute xmlatt in attCol)
            {
                listBox1.Items.Show(xmlatt);
            }
         }

//Rest of the code is for winform display(various buttons and boxes)
     }
}

After compiling this I am getting the error:

Expected class, delegate, enum, interface, or struct Type or namespace definition, or end-of-file expected

Please could you tell me what's the possible source of error and how to rectify it? I am a newbie in C#

+1  A: 

There's a space missing in the first line; should be "ref XmlNode" instead of "refXmlNode"

Edit: not the first line (any more); but the line that says:

private void AddingNodesToTree(refXmlNode xnode,TreeNode tnode)
lidgren
And as mentioned earlier, the "ref" is pointless here in the first place...
Jon Skeet
That was a typo. i am sorry. Still the errors are coming
And still you don't say *where*... Help us to help you.
Jon Skeet
i rectified the code and finally after some corrections the error that i am getting is "System.Windows.Forms.ListBox.ObjectCollection' does not contain a definition for 'Show'" in the line listBox1.Items.Show(xmlatt);How to remove this?
"Errors are coming" - you are getting an error message from the compiler, yes? It must be printing a number before the error - that number is the line-number at which the error appears. Could you tell us what is the line number, please?
scraimer
You probably want to replace listBox1.Items.Show(xmlatt); with listBox1.Items.Add(xmlatt); but this is getting kinda silly... I think you should call up someone to help you learn 1-on-1, and StackOverflow isn't the forum for that.
scraimer
Hello scraimer, well replacing show with add helped me a bit. it removed the compile time error at least. Now the error that is coming is Object reference not set to an instance of an object at line number XmlAttributeCollection attCol = currentElement.Attributes;Any idea how to remove it?