View Full Version : Populate combo box from xml
jerusking
02-09-2009, 01:32 PM
Hi Experts,
I would like to have a sample codes on how to populate combo box from xml using asp classic?
XML;
<ArrayOfGetCommunitydata>
<getCommunitydata>
<state_pk>1</state_pk>
<community_pk>1929</community_pk>
<community_name>Madrid</community_name>
</getCommunitydata>
<getCommunitydata>
<state_pk>35</state_pk>
<community_pk>1947</community_pk>
<community_name>Spain</community_name>
</getCommunitydata>
<getCommunitydata>
<state_pk>1</state_pk>
<community_pk>1909</community_pk>
<community_name>Brasil</community_name>
</getCommunitydata>
</ArrayOfGetCommunitydata>
FORM:
<select>
<option value="<community_pk>"> <community_name> </option>
</select>
Please any help or web site tutorials.
Thanks...
demtron
02-09-2009, 04:23 PM
Pwehaps this link will help:
http://forums.aspfree.com/asp-development-5/load-xml-from-external-domain-in-classic-asp-232724.html
Old Pedant
02-11-2009, 12:46 AM
Well, "demtron" showed you how to load the XML file from either a local file or from a remote url, but he didn't show how to process it.
For the sake of demoing, I'll assume you are getting the XML from an external URL. So, example coding:
<select name="yourChoiceOfName">
<%
Set xml = Server.CreateObject("msxml2.ServerXMLHTTP")
xml.open "GET", "http://www.somesite.com/path/to/data.xml", False
xml.send
Set doc = Server.CreateObject("msxml2.DOMDocument")
doc.loadXML( xml.ResponseXML.xml )
Set items = doc.getElementsByTagName("getCommunitydata")
For inum = 0 To items.length-1
Set curitem = items.item(inum)
Set pk = curitem.SelectSingleNode("community_pk")
Set nm = curitem.SelectSingleNode("community_name")
If Not( pk Is Nothing) AND Not( nm Is Nothing ) Then
pkval = Trim(pk.Text)
nmval = Trim(nm.Text)
Response.Write "<option value=""" & pkval & """>" & nmval & "</option>" & vbNewLine
End If
Next
%>
</select>
Untested, off the top of my head, but feels right.
If your xml file is local, then zap the three red lines of code and replace the
doc.loadXML( xml.ResponseXML.xml )
line with something like
doc.Load( Server.MapPath("/virtual/path/to/yourfile.xml") )
jerusking
02-11-2009, 12:29 PM
Well, "demtron" showed you how to load the XML file from either a local file or from a remote url, but he didn't show how to process it.
For the sake of demoing, I'll assume you are getting the XML from an external URL. So, example coding:
<select name="yourChoiceOfName">
<%
Set xml = Server.CreateObject("msxml2.ServerXMLHTTP")
xml.open "GET", "http://www.somesite.com/path/to/data.xml", False
xml.send
Set doc = Server.CreateObject("msxml2.DOMDocument")
doc.loadXML( xml.ResponseXML.xml )
Set items = doc.getElementsByTagName("getCommunitydata")
For inum = 0 To items.length-1
Set curitem = items.item(inum)
Set pk = curitem.SelectSingleNode("community_pk")
Set nm = curitem.SelectSingleNode("community_name")
If Not( pk Is Nothing) AND Not( nm Is Nothing ) Then
pkval = Trim(pk.Text)
nmval = Trim(nm.Text)
Response.Write "<option value=""" & pkval & """>" & nmval & "</option>" & vbNewLine
End If
Next
%>
</select>
Untested, off the top of my head, but feels right.
If your xml file is local, then zap the three red lines of code and replace the
doc.loadXML( xml.ResponseXML.xml )
line with something like
doc.Load( Server.MapPath("/virtual/path/to/yourfile.xml") )
wow...thanks Old Pedant...this is really useful and its working...many thanks to you...keep it up... ;-)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.