PDA

View Full Version : retrieving node attribute values from XML file


chris_angell
10-26-2007, 05:10 PM
hell I am trying to retrieving a nodes attributes.. but am failing.. :(

for example I have this XML

<description>

<attribute id="2" name="Colour">
<value id="212">red/pink</value>
</attribute>

</description>

I am trying to retrieve the value inside the nodes.. for example... 212 from id ans also 2 from attribure id ..

I am using Set xml = Server.CreateObject("Microsoft.XMLDOM") to connect to the xml... and this is fine..

i can pull out the tag values fine.. for example red/pink using
colours = xml.documentElement.childNodes(0).childNodes(1).childNodes(0).text

I have tried everything to get the id values and it is stumping me.. also i don't want to use xsl or go external of my asp page....

any help would be great

cheers chris

SouthwaterDave
10-27-2007, 11:21 AM
For this XML:<description>
<attribute id="2" name="Colour">
<value id="212">red/pink</value>
</attribute>
</description>
code:
Set x = Server.CreateObject("MSXML.DOMDocument")
x.load(Server.MapPath("x.xml"))
Response.Write x.documentElement.childNodes(0).childNodes(0).text
Response.Write "<br />"
Response.Write x.documentElement.childNodes(0).childNodes(0).GetAttribute("id")