hi...

i have given a code snippet below...
though i check for nullability before i do the actual processing... it still throws an unhandled exception.....

is there a way to handle this other than filling my code with try catch blocks....

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows.Forms;

namespace SSRS_Companion
{
    class DataSources
    {
        public string name = string.Empty;
        public string ID = string.Empty;
        public string reference = string.Empty;

        
        public void getContent(XmlNode node)
        {
                XmlElement nodeAsElement = node as XmlElement;
                //MessageBox.Show(node.InnerXml.ToString());
                if(nodeAsElement.HasAttribute("Name"))
                    this.name = new string(node.Attributes["Name"].Value.ToCharArray());
                
                node = nodeAsElement.GetElementsByTagName("rd:DataSourceID")[0];
                if(node!=null)
                    this.ID = new string(node.Value.ToCharArray());
                
                node = nodeAsElement.GetElementsByTagName("DataSourceReference")[0];
                if(node!=null)
                    this.reference = new string( node.Value.ToCharArray());
            
        }
    }
}

and here's the screenshot

Recommended Answers

In line 24 you are returning the elements of the node. [URL="http://msdn.microsoft.com/en-us/library/system.xml.xmlnode.value.aspx"]Elements[/URL] don't have a Value (look at the chart under Element).

Jump to Post

All 2 Replies

In line 24 you are returning the elements of the node. Elements don't have a Value (look at the chart under Element).

thanks again momerath :)