That worked, thanks a lot. Good to see these forums still rock.
-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Paulo Mouat
Sent: Friday, June 06, 2008 9:41 PM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] coding against missing xml
nodes/attributes
string myAttribute = null;
XmlAttribute someAttribute = configNode.Attributes["someAttribute"];
if (someAttribute != null)
myAttribute = someAttribute.Value;
Hope this helps,
//p
On Fri, Jun 6, 2008 at 9:19 PM, Smotrisky, Alex
<[EMAIL PROTECTED]> wrote:
> I've got an object called configNode of type
> System.Configuration.ConfigXmlElement.
>
> To read data from a config file I have code such as this:
>
> string myAttribute = configNode.Attributes["someAttribute"].Value;
>
> If the attribute is missing or incorrectly named then I get a
> System.NullReferenceException.
>
> Is there a way to check for attribute existence and such? Using try
> catch for this seems more like a last resort then the right way to
write
> the code.
>
>
>
> Thanks,
>
>
>
> Alex Smotritsky
>
>
>
>
>
> Thanks,
>
>
>
> Alex Smotritsky
>
> 212-698-0394
>
> [EMAIL PROTECTED]
>
>
>
>
> ===================================
> This list is hosted by DevelopMentor(R) http://www.develop.com
>
> View archives and manage your subscription(s) at
http://discuss.develop.com
>
===================================
This list is hosted by DevelopMentor(r) http://www.develop.com
View archives and manage your subscription(s) at
http://discuss.develop.com
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com