Results 1 to 1 of 1

Thread: Reading XML through a stream

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    1

    Reading XML through a stream

    Hi guys

    Am having an issue with reading a stream returning from a webserver as XML information - it seems to work fine to read it all, then when I try and go through it and pull out information its only returning the first lot of information regardless of how many blocks there are... The code is below - was wondering why it was returning the same values for each block (in the case below twice, as there are two blocks)


    Code:
            Dim tws As XmlWriter   
            Dim betty As New MemoryStream   
            tws = XmlWriter.Create(betty)   
      
            tws.WriteStartElement("Details")   
      
            ''---write xml code   
            tws.WriteStartElement("RequestSchedules")   
            tws.WriteElementString("dateStart", "10/11/2008")   
            tws.WriteElementString("dateEnd", "10/12/2008")   
            tws.WriteEndElement()   
      
            'close the XML file   
            tws.WriteEndElement()   
            tws.Close()   
      
            '---Read the memory stream and convert it back into a string   
            Dim xml_str As String = ""  
            xml_str = System.Text.Encoding.ASCII.GetString(betty.ToArray)   
            Dim WReq As WebRequestWebRequest = WebRequest.Create("https://" & MainApp.server & "/XML/interface/" & "?xml=" & xml_str)   
      
            '---read the contents of the file into a stream, and send it to the webserver   
            WReq.Method = "POST"  
            WReq.ContentType = "text/xml"  
            Dim wResp As WebResponse = WReq.GetResponse   
      
            Dim sr As StreamReader   
            sr = New StreamReader(wResp.GetResponseStream(), System.Text.Encoding.ASCII)   
            Dim server_response As String = sr.ReadToEnd   
            server_response = server_response.Substring(server_response.IndexOf("<"))   
      
            ''set up temp variables to hold xml element data   
            Dim appDate As String = ""  
            Dim appStart As String = ""  
            Dim appEnd As String = ""  
      
            Dim splits() As String   
            Dim holder As String   
            splits = Split(server_response, vbCrLf)   
      
            Dim x As Int64 = 0  
            While x < splits.Length  
                holder = splits(x)   
                If InStr(splits(x), "<Schedule>") Then   
                    Do   
                        x += 1   
                    Loop Until InStr(splits(x), "</Date>")   
                    appDate = splits(x).Substring(splits(x).IndexOf(">") + 1, (splits(x).IndexOf("<", 5) - splits(x).IndexOf(">")) - 1)   
      
      
       
      
                    Do   
                        x += 1   
                    Loop Until InStr(splits(x), "</startTime>")   
                    appStart = splits(x).Substring(splits(x).IndexOf(">") + 1, (splits(x).IndexOf("<", 5) - splits(x).IndexOf(">")) - 1)   
      
      
                    Do   
                        x += 1   
                    Loop Until InStr(splits(x), "</endTime>")   
                    appEnd = splits(x).Substring(splits(x).IndexOf(">") + 1, (splits(x).IndexOf("<", 7) - splits(x).IndexOf(">")) - 1)   
      
                    MsgBox(appStart)
                    MsgBox(appDate)                
                    MsgBox(appEnd)   
      
                Else   
                    x += 1   
                End If   
      
            End While

    Below is an example of the XML information being returned. The message boxes in the above code come up twice with the first date, the first start time and the first end time...

    Code:
    <?xml version="1.0"?>
    <Schedules>  
         <Schedule>  
              <Date>19/11/2008</Date>  
              <startTime>6:00am</startTime>  
              <endTime>11:00am</endTime>  
         </Schedule>  
         <Schedule>  
              <Date>19/11/2008</Date>  
              <startTime>1:00pm</startTime>  
              <endTime>3:30pm</endTime>  
         </Schedule>  
    </Schedules>
    Thanks for any help in advance!
    Last edited by Coruba67; Nov 22nd, 2008 at 02:58 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width