perfectxml.com
 Basic Search  Advanced Search   
Topics Resources Free Library Software XML News About Us
home » focus » msxml » ask a question » past questions & answers Friday, 12 October 2007
 
NEWS
MSXML 4.0 SP2 now available!

 
MSXML
Basics
DOM
SAX
XPath
XSLT
Schemas
SOM
HTTP Access
.NET
Data Islands
Ask a Question
   Past Q&As
C++ Samples
DLL/Version Info
Reference Guide
Books
KB Articles
   HOW TO
   SAMPLE
   INFO
   BUG/PRB
   FIX
   Misc.
MSXML Tips
   August 2002
   September 2002
MSXML Tools

Microsoft XML Core Services


Go back to list of previously asked questions and answers

Question: I would like to know how to post XML data from Visual Basic COM code to the ASP page. The XML data may contain international characters.
Asked By: Reddy Hari
Viewed: 3738
Answer: MSXML provides a class named XMLHTTP that is well suited for HTTP data access from the client side (for server side use ServerXMLHTTP). XMLHTTP is based on WinInet and is available on all the Microsoft platforms. Here is a small example of posting XML data from Visual Basic client code to the ASP page:

ASP Page::

<%
Set objDOM = Server.CreateObject("Msxml2.DOMDocument.4.0")
objDOM.async = false

If objDOM.load (Request) Then
	Response.ContentType = "text/xml"
	objDOM.save Response
Else
	Response.ContentType = "text/html"
	Response.Write "Error: " & Err.Description & objDOM.parseError.reason
End If
%>
The above server-side ASP code first creates the MSXML DOMDocument instance and loads the XML from the Request stream. If successful, sends the received XML back to the client (this is just an example), if it fails to load the document, sends the error description to the client.

Here is the Visual Basic client code that uses XMLHTTP to post XML to the above ASP page (remember to add reference to MSXML 4.0):

Dim objXMLHTTP As New MSXML2.XMLHTTP40

DataToSend ="<Data><Name>SomeName</Name><Type>FiancÚ</Type></Data>"

objXMLHTTP.Open "POST", "http://localhost/TestASP2/XMLPost.asp", False

objXMLHTTP.send DataToSend

MsgBox objXMLHTTP.responseXML.xml
MsgBox objXMLHTTP.responseText
The above Visual Basic 6.0 code lines first create the XMLHTTP40 instance and then call its Open method requesting a synchronous POST operation on the XMLPost.asp page. Next, it calls the XMLHTTP send method passing the XML string. This method actually send the HTTP request and waits for it to return. We can use the XMLHTTP Status and StatusText property to check for any HTTP errors and then use various response?????? properties (such as responseXML, responseText, etc.) to get the results returned.

Other Related Readings:
HOWTO: Submit Form Data by Using XMLHTTP or ServerXMLHTTP Object (Q290591)
HOWTO: Send a Binary Stream by Using XMLHTTP (Q296772)
HOWTO: Enable Compression and Decompression of Data By Using XMLHTTP Code (Q304279)
HOWTO: Use XSL to Transform Excel XML Spreadsheet for Server-Side Use (Q278976)


Go back to list of previously asked questions and answers
  Contact Us | E-mail Us | Site Guide | About PerfectXML | Advertise ©2004 perfectxml.com. All rights reserved. | Privacy