I've created an HTTP connection with a server. I send a WebRequest in XML to the server (see strReq in code) and it returns me a WebResponse. This response is inserted in a string, which is then loaded into a XmlDocument. How can I parse this XmlDocument? I tried a few things, but I didn't get it to work. The output which is in de XmlDocument is like this:
<?xml version="1.0" encoding="iso-8859-1" ?>
<antwoord type="ack">T08-13995</antwoord>
I need the piece of code that is on the second line between <antwoord> and </antwoord>. Does anyone have an idea on how to go about that?
Below is the code I use for the WebRequest and the WebResponse:
Expand|Select|Wrap|Line Numbers
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Dim sp_response As XmlDocument = New XmlDocument()
- Dim strReq, strRsp, url As String
- Dim httpReq As HttpWebRequest
- Dim httpRsp As HttpWebResponse
- Dim streamReq, streamRsp As Stream
- Dim sw As StreamWriter
- Dim sr As StreamReader
- url = "http://..."
- Try
- httpReq = WebRequest.Create(url)
- httpReq.Method = "POST"
- httpReq.KeepAlive = False
- httpReq.UserAgent = Nothing
- httpReq.ContentType = "text/xml"
- streamReq = httpReq.GetRequestStream
- sw = New StreamWriter(streamReq)
- strReq = "<?xml version='1.0' encoding='UTF-8'?><lmsvraag nummer='464312'/>"
- sw.Write(strReq)
- sw.Close()
- httpRsp = httpReq.GetResponse
- streamRsp = httpRsp.GetResponseStream
- sr = New StreamReader(streamRsp)
- strRsp = sr.ReadToEnd
- httpRsp.Close()
- sp_response.LoadXml(strRsp)
- Debug.WriteLine(strRsp)
- Catch ex As Exception
- Debug.WriteLine("EXCEPTION")
- Debug.WriteLine("Error #" + ex.Message)
- Debug.WriteLine("Error reported by " + ex.Source)
- End Try
- End Sub
Cheers,
Steven