How to check if Attribute exists in Child Node

How can i access the type Attributes directly if my XmlNode holds the below xml file.

i tried the following with no luck
dim elementPath as String = "ns:RequestedAddr/ns:type"
dim elementPath as String = "ns:RequestedAddr/type"
dim elementPath as String = "RequestedAddr/type"

Dim myNode As XmlNode = node.Attributes(elementPath)

I need to check if the node / Attribute exists to avoid null exceptions

        <RequestedAddr type="unknown">12099925140</RequestedAddr>
        <DestAddr type="e164">+12099925140</DestAddr>
        <RoutedAddr type="national">2099925140</RoutedAddr>
        <CallingPartyRoutedAddr type="national">2099313552</CallingPartyRoutedAddr>
        <CallingPartyOrigAddr type="national">2099313552</CallingPartyOrigAddr>

Open in new window

Confused CoderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What XML element the "node" object refers to? Is it "RoutingInfo" or one of its children?
If it is "RoutingInfo", then you first get a reference to a child, like
and then use the GetAttribute() method:
Set RequestedAddr = node.SelectSingleNode("ns:RequestedAddr")
type_string = RequestedAddr.GetAttribute("ns:type")

Open in new window

I am not sure, will the following work or not, but you could try
Set RequestedAddr_type_attr = node.SelectSingleNode("ns:RequestedAddr/@ns:type")
if not RequestedAddr_type_attr is Nothing then type_string = RequestedAddr_type_attr.Value

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.