[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

display result from xml file

Posted on 2006-11-01
6
Medium Priority
?
169 Views
Last Modified: 2012-05-05
Hi Experts
I have the following xml:
<?xml version="1.0"?>
<!--This Is A List Of Dream Vacations Special Packages-->
<HOTELS>
  <HOTEL>
    <DEPARTURE>Toronto</DEPARTURE>
    <DESTINATION>Cancun</DESTINATION>
    <NAME>AKUMAL BEACH RESORT</NAME>
    <LINK>http://webstar.softvoyage.com/cgi-bin/hotel_desc.cgi?sun&&http://webstar.softvoyage.com/hotels/VACen/AKUMCUN.html</LINK>
    <STAR>3</STAR>
    <ROOM>STD-GARD</ROOM>
    <MEAL>AI</MEAL>
    <DATE>NOV-15-2006</DATE>
    <DURATION>7</DURATION>
    <PRICE>$822.00</PRICE>
    <SID>112086a3259303c76d123e67e7004be2</SID>
    <URL>http://sun.sax.softvoyage.com/cgi-bin/resultsforf.cgi?sid=112086a3259303c76d123e67e7004be2</URL>
  </HOTEL>
  <HOTEL>
    <DEPARTURE>Toronto</DEPARTURE>
    <DESTINATION>Cancun</DESTINATION>
    <NAME>AKUMAL BEACH RESORT</NAME>
    <LINK>http://webstar.softvoyage.com/cgi-bin/hotel_desc.cgi?sun&&http://webstar.softvoyage.com/hotels/VACen/AKUMCUN.html</LINK>
    <STAR>3</STAR>
    <ROOM>SUP</ROOM>
    <MEAL>AI</MEAL>
    <DATE>NOV-15-2006</DATE>
    <DURATION>7</DURATION>
    <PRICE>$863.00</PRICE>
    <SID>112086a3259303c76d123e67e7004be2</SID>
    <URL>http://sun.sax.softvoyage.com/cgi-bin/resultsforf.cgi?sid=112086a3259303c76d123e67e7004be2</URL>
  </HOTEL>
</HOTELS>

And im using the following code which  should display the result of each node on the page but it gives me the result of first node every time. Im using the following code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim doc As New XmlDocument
        Dim hotelNodes As XmlNodeList
        Dim node As XmlNode
        Dim strDep, strDes, strName, strLink, strStar, strRoom, strMeal, strDate, strDuration, strPrice, strSID, strURL As String
        Dim lbl As Label
       
       
        Dim hl As HyperLink
        Dim tbl As New Table
        Dim tr As TableRow
        Dim tc As TableCell
        Dim i As Integer
        doc.Load("C:\Inetpub\wwwroot\CallForm\Specials\special.xml")

        hotelNodes = doc.SelectNodes("//HOTELS/HOTEL")

        i = 1

        For Each node In hotelNodes
            strDep = node.SelectSingleNode("//DEPARTURE").InnerText
            strDes = node.SelectSingleNode("//DESTINATION").InnerText
            strName = node.SelectSingleNode("//NAME").InnerText
            strLink = node.SelectSingleNode("//LINK").InnerText
            strStar = node.SelectSingleNode("//STAR").InnerText
            strRoom = node.SelectSingleNode("//ROOM").InnerText
            strMeal = node.SelectSingleNode("//MEAL").InnerText
            strDate = node.SelectSingleNode("//DATE").InnerText
            strDuration = node.SelectSingleNode("//DURATION").InnerText
            strPrice = node.SelectSingleNode("//PRICE").InnerText
            strSID = node.SelectSingleNode("//SID").InnerText
            strURL = node.SelectSingleNode("//URL").InnerText

           
            tr = New TableRow
            tc = New TableCell
           
            lbl = New Label
            lbl.ID = "lbl" & i
            lbl.Text = "<br>Departure: "
            tc.Controls.Add(lbl)
            lbl = New Label
            lbl.ID = "lbl2" & i
            lbl.Text = "<b>" & strDep & "</b></br>"
            tc.Controls.Add(lbl)
            tr.Cells.Add(tc)
            tbl.Rows.Add(tr)
           
            lbl = New Label
            lbl.ID = "lbl" & i
            lbl.Text = "Destination: "
            tc.Controls.Add(lbl)
            lbl = New Label
            lbl.ID = "lbl2" & i
            lbl.Text = "<b>" & strDes & "</b></br>"
            tc.Controls.Add(lbl)
            tr.Cells.Add(tc)
            tbl.Rows.Add(tr)
           
            lbl = New Label
            lbl.ID = "lbl" & i
            lbl.Text = "Hotel: "
            tc.Controls.Add(lbl)
            hl = New HyperLink
            hl.ID = "h1" & i
            hl.Text = strName
            hl.NavigateUrl = strLink
            tc.Controls.Add(hl)
            tr.Cells.Add(tc)
            tbl.Rows.Add(tr)
           
            tr = New TableRow
            tc = New TableCell
            lbl = New Label
            lbl.ID = "lbl" & i
            lbl.Text = "Star Rating: "
            tc.Controls.Add(lbl)
            lbl = New Label
            lbl.ID = "lbl2" & i
            lbl.Text = "<b>" & strStar & "</b>"
            tc.Controls.Add(lbl)
            tr.Cells.Add(tc)
            tbl.Rows.Add(tr)
           
            tr = New TableRow
            tc = New TableCell
            lbl = New Label
            lbl.ID = "lbl" & i
            lbl.Text = "Room Type: "
            tc.Controls.Add(lbl)
            lbl = New Label
            lbl.ID = "lbl2" & i
            lbl.Text = "<b>" & strRoom & "</b>"
            tc.Controls.Add(lbl)
            tr.Cells.Add(tc)
            tbl.Rows.Add(tr)
           
            tr = New TableRow
            tc = New TableCell
            lbl = New Label
            lbl.ID = "lbl" & i
            lbl.Text = "Meal: "
            tc.Controls.Add(lbl)
            lbl = New Label
            lbl.ID = "lbl2" & i
            lbl.Text = "<b>" & strMeal & "</b>"
            tc.Controls.Add(lbl)
            tr.Cells.Add(tc)
            tbl.Rows.Add(tr)
           
            tr = New TableRow
            tc = New TableCell
            lbl = New Label
            lbl.ID = "lbl" & i
            lbl.Text = "Date: "
            tc.Controls.Add(lbl)
            lbl = New Label
            lbl.ID = "lbl2" & i
            lbl.Text = "<b>" & strDate & "</b>"
            tc.Controls.Add(lbl)
            tr.Cells.Add(tc)
            tbl.Rows.Add(tr)
           
            tr = New TableRow
            tc = New TableCell
            lbl = New Label
            lbl.ID = "lbl" & i
            lbl.Text = "Duration: "
            tc.Controls.Add(lbl)
            lbl = New Label
            lbl.ID = "lbl2" & i
            lbl.Text = "<b>" & strDuration & "</b>"
            tc.Controls.Add(lbl)
            tr.Cells.Add(tc)
            tbl.Rows.Add(tr)
           
            tr = New TableRow
            tc = New TableCell
            lbl = New Label
            lbl.ID = "lbl" & i
            lbl.Text = "Price: "
            tc.Controls.Add(lbl)
            lbl = New Label
            lbl.ID = "lbl2" & i
            lbl.Text = "<b>" & strPrice & "</b>"
            tc.Controls.Add(lbl)
            tr.Cells.Add(tc)
            tbl.Rows.Add(tr)
                       
            tr = New TableRow
            tc = New TableCell
            hl = New HyperLink
            hl.ID = "h2" & i
            hl.NavigateUrl = strURL
            'hl.NavigateUrl = "http://sun.sax.softvoyage.com/cgi-bin/input-verifforf.cgi?sid=" & strSID
            hl.Text = "<b>" & "Request Space" & "</b></br>"
            tc.Controls.Add(hl)
            tr.Cells.Add(tc)
            tbl.Rows.Add(tr)
     
       i += 1
        Next
        Page.Controls.Add(tbl)
     End Sub

This code traverse through each node but displaying the values of first node every time. Can anyone help me..?

Best Regards
Shaukat
0
Comment
Question by:shwaqar82
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 17853842
Hi shwaqar82,

get rid of the "//" in the childnodes
strDep = node.SelectSingleNode("DEPARTURE").InnerText


Cheers!
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 17854059
shwaqar82,

the "//" makes you start at the root node all over again for every HOTEL
pointing at the first each time

since DEPARTURE is a direct child, you should just put the name there, not the // in front of it

cheers

Geert
0
 

Author Comment

by:shwaqar82
ID: 17854922
i did that but still gives me the same result
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:shwaqar82
ID: 17858053
Hi Geert

It works now thanks for you precious help on time.

Best Regards
Shaukat
0
 

Author Comment

by:shwaqar82
ID: 17858093
Can you help me in displaying the nodes information row wise. I mean i wana display the information like below:

Hotel 1 Information                       Hotel 2 Information
Hotel 3 Information                       Hotel 4 Information
Hotel 5 Information

Right now it displays the information like that:

Hotel 1 Info.
Hotel 2 Info.
Hotel 3 Info.
....

That would be great if you fixed it.

Best Regards
Shaukat Waqar
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 17876648
Hi,

I am not really a VB (script) programmer

What you could do is the following

For Each node In hotelNodes
you could only loop over the hotelNodes with a position mod 2 = 1
and so create the rows
and pick the following node inside the row

If you can't manage that yourself, you can post in the VB(script) TA

cheers
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

650 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