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

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.