Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

looping through XML file with asp

Status
Not open for further replies.

guestAsh

Technical User
Feb 27, 2004
65
GB
Hi i have built an XML file to hold some flight details see below:

Code:
<?xml version="1.0"?>
<routes>
<route from="London Heathrow" to="New York" duration="07:30" >
<airline code="BA" aircraft="777"/>
<airline code="BA" aircraft="747-400"/>
<airline code="CO" aircraft="777"/>
<airline code="CO" aircraft="767-2000"/>
</route>
<route from="Edinburgh" to="New York" duration="08:55" via="LHR" transfer="02:00">
<airline code="BA" aircraft="777"/>
<airline code="BA" aircraft="747-400"/>
<airline code="CO" aircraft="777"/>
<airline code="CO" aircraft="767-2000"/>
</route>
<route from="Edinburgh" to="New York" duration="">
<airline code="CO" aircraft="757-200"/>
</route>
</routes>

i've then used the following ASP to loop through each record:
Code:
Response.Write "<table class='bluetable'>"
Response.Write "<tr><th>To:</th><th>From:</th><th>Via:</th><th>Approx Flight duration (hrs):</th><th>Approx transfer time  (hrs):</th><th>Airline(s):</th><th>Comments:</th></tr>"
For Each route in objXML.documentElement.SelectNodes("/routes/route")

Response.Write "<tr><td>"
Response.Write route.GetAttribute("to")
Response.Write "</td>"
Response.Write "<td>"
Response.Write route.GetAttribute("from")
Response.Write "</td>"
Response.Write "<td>"
Response.Write route.GetAttribute("via")
Response.Write "</td>"
Response.Write "<td>"
Response.Write route.GetAttribute("duration")
Response.Write "</td>"
Response.Write "<td>"
Response.Write route.GetAttribute("transfer")
Response.Write "</td>"
Response.Write "<td>"
...
Next
....


which work fine, but now what i want to do is list each "code" attribute for the child "airline".
so for example it would just list BA, BA, CO, Co for the first record and the BA, BA, CO,Co for the 2nd etc...

I've tried using:

Code:
For Each airline in objXML.documentElement.SelectNodes("/routes/route/airline")
Response.Write airline.GetAttribute("code")
but this just list every airline child. any help will be of much help!

thanks

Ash
 
>For Each airline in objXML.documentElement.SelectNodes("/routes/route/airline")

[1] If you want each airline under specific route (obj reference of the for-loop), it is this.
[tt] For Each airline in [red]route[/red].SelectNodes("[red]airline[/red]")[/tt]
[2] If, in case, you want _unique_ airline company under the specific route (obj reference of the for-loop), it is this.
[tt] For Each airline in [red]route[/red].SelectNodes("[red]airline[not(@code = preceding-sibling::airline/@code)][/red]")[/tt]
In this latter case, first route will result in airlines with @code of ("BA","CO"), the second of ("BA","CO") and the third of ("CO") only.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top