List Info

Thread: coding against missing xml nodes/attributes




coding against missing xml nodes/attributes
user name
2008-06-06 20:19:56
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

alex.smotritskygenzyme.com

 


===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )