Hi,
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: -
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
-
Thnx for your help in advance!
Cheers,
Steven
3 1539
Hi ,
You can try the following code in the code that you have written:
e.g. -
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)
-
-
-
'' Process xml from xmldocument ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
-
-
Dim xmlNodeList As XmlNodeList
-
-
''Get the xmlNodeList with the name as "antwoord"
-
-
xmlNodeList = _doc.GetElementsByTagName("antwoord")
-
-
-
For index As Integer = 0 To xmlNodeList.Count - 1
-
''Get the value of each selected node
-
MsgBox(xmlNodeList.Item(index).InnerText)
-
Next '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
-
-
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
-
Hi, thanks a lot, works like charm! Now something else:
The response by the server is, like I said, as follows:
<?xml version="1.0" encoding="iso-8859-1" ?>
<antwoord type="ack">T08-13995</antwoord>
The type in the Antwoord-node can be either "ack", as shown above, or it can be "error". Is there any way to check what the value of the type is?
Thnx,
Steven
Has anyone got an idea on my last question?
Thnx in advance,
Steven
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Robert Mark Bram |
last post by:
Hi all!
I want to use asp to do text find and replace with XHTML elements.. for
example, let's say I have the following XHTML:
<note>
<from id="123">Jani</from>
<to>Tove</to>
<message>Norwegian: æøå. French: êèé</message>
</note>
|
by: Thomas Polan |
last post by:
Sorry if this has been posted before...
I am receiving XML messages over a TCP client. Messages vary in size and
sometimes can arrive in groups. Thus, I am not guaranteed to receive a full
message in a single read from my socket.
I am loading each message into an XmlDocument after it arrives. I need a
way to make sure I have a complete XML message before I load it into an
XmlDocument or it will throw an exception. I am currently...
|
by: sunil |
last post by:
I am creating a XML document which opens fine in IE. Implies MSXML
thinks it is a well formed document.
But when I try to load this document in VB.net using the following
code
Dim doc As New XmlDocument
doc.Load("C:\Projects\SQLXML\corc.xml")
I get the following error:
"System.Xml.XmlException: An unexpected end of file parsing CDATA has
|
by: Erik Moore |
last post by:
I am both producing and parsing an xml document that needs to be validated against a schema. I wanted some consumers of the document
to have the option of not performing a validation, so I left the nodes in the instance unqualified. An example of the document is
below:
<?xml version="1.0" encoding="utf-8" ?>
<filingreceipt xmlns="http://www.disclosureusa.org/filingreceipt.xsd">
<cpofilingnumber>TX2004043037501</cpofilingnumber>...
|
by: Anthony Boudouvas |
last post by:
Hi to all,
i have a very simple XML file that i present to a user and i will allow
him/her
to manualy edit it and send it back to a listening server.
What is the best -simple- way to parse it so it does not contain anything
invalid after edit ??
I just need a simple data validation, no xml-schemas etc...
| |
by: Dinçer |
last post by:
I need to parse an XML file and print the contents of it on an aspx page. My
XML file structure is like this:
<QueryResult>
<messageNo>1</messageNo>
<messageText />
<HERE>
<ExternalIntegrator><Entities>
<name>John</name>
<surname>Carpenter</surname>
|
by: Mark |
last post by:
Hi...
We've been doing some basic performance testing comparing asp, asp.net,
mono, and php. One of the basic tests is on simply parsing an xml document
and streaming the result back to the client.
I never would have thought of it, but someone in our group had heard that
using XmlDocument.Load (Server.MapPath (file));
was slower than actually creating the stream, the XmlTextReader, and passing
the reader to the XmlDocument.Load();.
|
by: george |
last post by:
Hi,
I am parsing a XML string (see code below) by loading into XMLDocument and
selecting certain node (Result) and loop through it. Instead of using
item(), is there a way to get the element value by name?
Also, is there a way to using the XmlTextReader to move to Search/Result and
then loop though each node?
|
by: danep |
last post by:
Hi, I'm fairly new to AJAX, but I've been able to retrieve HTML and
plain-text documents without any trouble. However, I haven't figured
out how to retrieve it in XML format. Basically, here's the script
that's supposed to retrieve and parse the data when you pass it the url
of the page generating the XML data:
<script type="text/javascript">
var xmlHttp
function getresponse(url)
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |