Select value of attribute in xml through ASP

Can you someone help with how to get the value of date to be displayed right before the description in the code below,

thank you,

xml:
<%
strDate = "4/18/2006"
intMaxEvents = 3


Set oXMLHTTP = Server.CreateObject("Microsoft.XMLDOM")
oXMLHTTP.async = False
<?xml version="1.0" encoding="UTF-8"?>
<calendar>
     <events>
          <event date="4/17/2006">
               <description>Party</description>
          </event>
          <event date="4/20/2006">
               <description>Work</description>
          </event>
          <event date="4/17/2006">
               <description>Run Marathon</description>
          </event>
          <event date="4/17/2006">
               <description>Recover</description>
          </event>
          <event date="4/20/2006">
               <description>Another Item on another day</description>
          </event>
     </events>
</calendar>

ASP:

If oXMLHTTP.Load(Server.MapPath("calendar.xml")) Then
     Set oEventNodes = oXMLHTTP.documentElement.selectNodes("//event[@date>='" & strDate & "']")
     Response.Write "<ul>"    
     For i = 0 To (oEventNodes.Length - 1)
          Response.Write "<li>" & oEventNodes.Item(i).SelectSingleNode("description").Text & "</li>"
          If i = (intMaxEvents - 1) Then Exit For
     Next    
     Response.Write "</ul>"
Else
     Response.Write "XML file did not load"
End If
Set oXMLHTTP = Nothing
%>
tamilgirl77Asked:
Who is Participating?

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

x
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.

peterxlaneCommented:
Like this:

Response.Write "<li>" & oEventNodes.Item(i).SelectSingleNode("@date").Text & "</li>"

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
deighcCommented:
- oEventNodes is a collection of <event> node objects.
- A node object has an attributes collection, and this collection has a getNamedItem method which returns an attribute object
- The attribute object has a value property

So, to access the 'date' attribute of the <event> node inside your For...Next loop try something like this

oEventNodes.item(i).atttributes.getNamedItem("date").value
peterxlaneCommented:
@deighc - Is there an advantage to doing it the way you suggested compared to the way I did it?  I work a fair amount with XSL, so it seemed intuitive for me to just provide an XPath allow with the SelectSingleNode method, but I am curious if your way may have some advantages that I am not aware of...
deighcCommented:
> Is there an advantage to doing it the way you suggested compared to the way I did it?

No.

It was my understanding that attributes could only be accessed programatically through the attributes collection. I didn't realise that they were also accessible by using the SelectSingleNode() method. But this makes sense since an XML parser builds a 'node tree' from all element and attribute nodes.

So:
- I've learned something
- @tamilgirl77, please don't accept my answer over @peterxlane's as they're functionally identical
tamilgirl77Author Commented:
Thank you both for helping me out,
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
Web Languages and Standards

From novice to tech pro — start learning today.