Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

count xml nodes in ASP

Question posted by: norulzs (Newbie) on March 26th, 2008 05:43 PM
Hi i have the following xml

<heroes>
<character>
....
</character>
<character>
....
</character>
<character>
....
</character>
<character>
....
</character>
</heroes>

i have the follwoing asp code to load in

heroXML = request.form("searchXML")

set xmlDoc = createObject("Microsoft.XMLDOM")

xmlDoc.async = False
xmlDoc.loadxml(heroXML)

My question is whats the best way to work out the number of <character> nodes in my lump of xml, this question has been answered in javascript and i have tried using
xmlDoc.childnodes.length but that keeps on returning back 1 even when i have multiple <character> nodes in my xml.

Thanks.
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
norulzs's Avatar
norulzs
Newbie
9 Posts
March 26th, 2008
06:32 PM
#2

Re: count xml nodes in ASP
got it to give me what i wanted by using

dim i, Node
i=0

set xmlNC = xmlDoc.selectSingleNode("heroes")

for each Node in xmlNC.selectNodes("character")
i = i + 1
next

response.write("child nodes="&i)

Reply
Reply
Not the answer you were looking for? Post your question . . .
169,970 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top ASP Forum Contributors