XML with ASP - Displaying Attribute

sfak_man
sfak_man used Ask the Experts™
on
Hi Experts,

This one has had me stumped so I’ve given up, signed up and I hope you can help me.

I’m simply trying to pull in the following XML feed to an HTML list menu using ASP/VBScript:

URL for the feed:
http://dgcsc.org/goldprices2.xml

Example Feed:
<GoldPrice per="gram" date="2010-01-31 17:26:53">

<Price currencyname="Argentine Peso" currencycode="ARS">
<Ask>109.8112</Ask>
<Bid>109.3623</Bid>
</Price>

Example result:

  <select name="dlCurrency" id="dlCurrency">
    <option value=”109.8112"> Argentine Peso (ARS) </option>
  </select>

Obviously I would like the list to loop through all the values in the XML feed so I have a complete list of currencies and their values.

The code I’ve been using is below. I’m almost there (just can’t pull in the Attribute!).

Thanks,

Georgio

<%
Response.Buffer = True

Dim URL, objXML
URL = "http://dgcsc.org/goldprices2.xml"
set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.setProperty "ServerHTTPRequest", True
objXML.async =  False
objXML.Load(URL)
 
If objXML.parseError.errorCode <> 0  Then
      Response.Write(objXML.parseError.reason)
      Response.Write(objXML.parseError.errorCode)
End If


' Date & Weight
For each objAttribute in objXML.documentElement.attributes
      response.write objAttribute.childNodes.item(0).Text & "<BR>"
Next

%>
  <select name="dlCurrency" id="dlCurrency">
    <%
      ' Values
      For each objChild in objXML.documentElement.childNodes
      %>
    <option value="<%=objChild.childNodes.item(0).Text%>">*currency_name*</option>
        <% Next %>
  </select>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
here you go
<%
Response.Buffer = True

Dim URL, objXML
URL = "http://dgcsc.org/goldprices2.xml"
set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.setProperty "ServerHTTPRequest", True
objXML.async =  False
objXML.Load(URL)
 
If objXML.parseError.errorCode <> 0  Then
      Response.Write(objXML.parseError.reason)
      Response.Write(objXML.parseError.errorCode)
End If


' Date & Weight
For each objAttribute in objXML.documentElement.attributes
      response.write objAttribute.childNodes.item(0).Text & "<BR>"
Next

%>
  <select name="dlCurrency" id="dlCurrency">
<%
		Set objLst = objXML.getElementsByTagName("Price")
		For i = 0 to (objLst.length - 1)
%>
			<option value="<%=objLst.item(i).selectSingleNode("Ask").text%>"><%=objLst.item(i).attributes.getNamedItem("currencyname").nodeValue%></option>
<% 
		Next 
%>
  </select>

Open in new window

Author

Commented:
Thank you very much - that's great!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial