Click to See Complete Forum and Search --> : get id attribute?


daddywhite
05-11-2006, 07:58 AM
I have the following XML file:

<?xml version="1.0"?>
<widgets>
<widget id="1">
<name>Oblong Widget</name>
<productNumber>3432341-12312</productNumber>
<cost>45.50</cost>
<description>This widget is useful for jobs requiring
oblong tools.</description>
</widget>

<widget id="2">
<name>Skinny Widget</name>
<productNumber>34323341-1F11</productNumber>
<cost>55.75</cost>
<description>This widget is useful for jobs requiring
skinny tools.</description>
</widget>
</widgets>

And I am using the below bit of ASP to loop and display the data:

<%
Dim objXMLDOM
Set objXMLDOM = Server.CreateObject("Microsoft.XMLDOM")

'load the widget.xml document
objXMLDOM.load(Server.MapPath("widget.xml"))

Set nodeList = objXMLDOM.documentElement.getElementsByTagName("widget")

For i=0 to nodeList.length-1

Set node = nodeList(i)
For j=0 to node.ChildNodes.length-1
Response.Write nodeList(i).ChildNodes(j).nodeName &" : " & node.ChildNodes(j).Text & "<br>"
Next
Response.Write "<br>------------------------<br><br>"

Next
%>

I am tring to also display the id attribute for each record in the XML file. ie widget id="1" etc.

Any ideas?

Thanks.

Stephen Philbin
05-11-2006, 09:28 AM
I don't really do .Net or ASP, but looking at that code, I'd guess it to be Response.Write node.getAttribute("id")

Also, please try to remember to use the forums code tags. It just makes things a bit more readable for folks trying to help. Thanks. ;)

daddywhite
05-12-2006, 04:40 AM
Thats great

Regards
Dave.

Stephen Philbin
05-12-2006, 11:19 AM
Happy to help. ;)