Link to home
Start Free TrialLog in
Avatar of rwallacej
rwallacej

asked on

VB.net - XML node, check attribute exists

How do I check if an attribute exists in xml node

This, as expected, throws a null pointer.....but checking if the attribute exists in first place is surely better than catching exceptions?

Dim node As XmlNode = whatever
....
Dim x as String
x = node.Attributes.GetNamedItem("fieldDoesntExist").Value


Thanks
ASKER CERTIFIED SOLUTION
Avatar of tpwells
tpwells

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Use

result = element.hasAttribute(attName)

Avatar of rwallacej
rwallacej

ASKER

Dimandja
this is what I'm looking for rather than a for loop, but its a node I've got, not an element......
the node is from an XmlNodeList
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks