Solved

Extracting Data from XML

Posted on 2006-07-20
3
250 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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
DOCTYPE in pubmed 5 43
VB.NET WEb Service complex type 14 57
SQL Remove Elements from XML 6 39
Parsing the XML data to SQL Server 4 50
The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

16 Experts available now in Live!

Get 1:1 Help Now