Solved

Extracting Data from XML

Posted on 2006-07-20
3
251 Views
Last Modified: 2012-06-22
Hi

My first task was to : extract country code and country name values in a combo box:

I did this and here is my code:

====================================
'ASP Code start here:

Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
      objXMLDoc.async = False
      objXMLDoc.loadXML("countries.xml")
      

Response.Write "<form action='getCity.asp' method='post'>"

%>
<select name="txtCountryID" onChange="window.open(this.options[this.selectedIndex].value,'_self')">
<%

      'Response.Write "<option value='' selected>Select Country</option>"
      
      Set NodeList2 = objXMLDoc.getElementsByTagName("CoID")
      Set NodeList = objXMLDoc.getElementsByTagName("Country")
      
      
      numNodes2 = NodeList2.Length
      
      For i = 1 To NumNodes2
               Set CurrNode2 = NodeList2.nextNode
               Set CurrNode = NodeList.nextNode
               Response.Write "<option value='getCity.asp?CountryID="&CurrNode2.text&"&Country="&CurrNode.text&"'>"&CurrNode.text&"</option>"
      Next

      Response.Write "</select>"
      Response.Write "</form>"
'Asp Code End here
============================================


============================================
'short version of my XML file
<?xml version="1.0" encoding="utf-8" ?>
- <CountriesCities>
- <Countries>
  <CoID>111</CoID>
  <Country>ALBANIA</Country>
  <Cities CiID="1478" City="TIRANA" />
  </Countries>
- <Countries>
  <CoID>1</CoID>
  <Country>AUSTRALIA</Country>
  <Cities CiID="1" City="ADELAIDE" />
  <Cities CiID="4" City="MELBOURNE" />
  <Cities CiID="6" City="SYDNEY" />
  </Countries>
- <Countries>

'XML file end here
============================================

Until here I am fine.

My problem is:

I have now the countries in the combo on the first page. On the next page, I want another combo, with the cities from selected country.


Clarification: if on the first page selected country was Albania, I would like to get Tirana only in my combobox, and if selected country was Australia to get: ADELAIDE, MELBOURNE and SYDNEY

The very same as in the country combo, ID is the value and the name is displayed in the combo.

Anyone can help?

Regards, Zoran
0
Comment
Question by:zoran_m
3 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 17219231
Hi zoran_m,

It seems to me that all you need is a way to select the cities based on the country
and that you can deal with the rest yourself

instead of using the
Set NodeList = objXMLDoc.getElementsByTagName("Country")

you can use
Set NodeList = objXMLDoc.SelectNodes("//Countries[Country = 'AUSTRALIA']/Cities/@City")

selectnodes allows you to select nodes based on an XPath expression
the expression is a string so you can construct it through concatenation with the country name as a variable eg.

Cheers!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Merging XML files via VB Script 4 79
VB.NET XML Processing a XMLNodeList with Namespace 16 66
Change to event 1 101
Issue with XSLT mapping 10 15
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now