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...
Thanks for any help in advance!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>


Reply With Quote