Infrequent existence of node in xml elements

 <ObjectArrayToXml xmlns="">
**here the tag of AgentName will be missing

we are getting the above structure with all 3 tags Pass,AgentName,Document for each item for more than 4 years
we been pharsing and printing it successfully like that:

Set NodeList = xmlDoc.documentElement.selectNodes("//ObjectArrayToXml/itemslist/ItemInfo")
     For Each Node In NodeList
response.write Node.selectSingleNode("Pass").text
response.write Node.selectSingleNode("AgentName").text
response.write Node.selectSingleNode("Document").text   

the structure of xml was changed and now we are not always getting the tag of AgentName – it might not come at all for some of items.
I need to check now if tag exist for each item, then i wrote this code:

set xxx = xmlDoc.selectSingleNode("//AgentName")
If Not xxx Is Nothing Then
response.write Node.selectSingleNode("AgentName").text
End If

it works great if ALL items has this tag or if ALL items doesn’t have this tag. BUT once some items have this tag and others ain’t then page crashes and i gives 500 error.
I realized that xmlDoc.selectSingleNode(“//AgentName”) must looking the first item only and assume that all the rest items has same taga, and not checking each and every one of items for existance of AgentName tag.
I might not be right, can you advice how to check if this tag exist in each item?

Source: xml

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.