Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP XML
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP XML Using ASP 3 and XML. See also the XML category for more XML discussions not relating to ASP. NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP XML section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 17th, 2003, 09:47 AM
Registered User
 
Join Date: Dec 2003
Location: grenoble, , France.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Encoding problems with XMLHTTP

Hi,
I have a VB application which sends an XML file (a login) using SOAP to an ASP page. And then the ASP page checks the login, once done it returns a Text which the listening VB application loads to a DOMDocument.

My problem is : when the VB (client) App runs on Windows2000,
the XMLHTTP response.text method won't get the file correctly if it is encoded in ISO-8859-1.
There are question marks instead of accentued characters.

Everything works fine when the VB (client) App runs on Windows XP...

I have tried different regional settings with no result.

Any help will be greatly appreciated!!!
////////////////////////////////////////////////////////////////
VB app:
Dim obj2XMLHTTP As New MSXML.XMLHTTPRequest
    Dim str2MethodResultXML

    Dim strMethodPkg2 As String

           strMethodPkg2 = "<SOAP:Envelope xmlns:SOAP=""http://schemas.xmlsoap.org/soap/envelope/"">"
           strMethodPkg2 = strMethodPkg2 & "<SOAP:Header></SOAP:Header>"
           strMethodPkg2 = strMethodPkg2 & "<SOAP:Body><m:ImportOrders xmlns:m=""urn:soapserver/soap:AuthorizationModule"">"
           strMethodPkg2 = strMethodPkg2 & "<LoginOK>" & "MyLogin" & "</LoginOK>"
           strMethodPkg2 = strMethodPkg2 & "</m:ImportOrders></SOAP:Body></SOAP:Envelope>"
           obj2XMLHTTP.open "post", "http://SomeURL.asp", False

           obj2XMLHTTP.setRequestHeader "Content-Type", "text/xml"
               obj2XMLHTTP.setRequestHeader "SOAPAction", "soapserver/soap:AuthorizationModule#ImportOrders"

           obj2XMLHTTP.send strMethodPkg2

           str2MethodResultXML = obj2XMLHTTP.responseText
           xmldoc.async = False
           xmldoc.loadXML str2MethodResultXML
/////////////////////////////////////////////////////////////////
ASP Page:

<%Set obj2XMLDOM = Server.CreateObject("Microsoft.XMLDOM")

'**uses the obj2XMLDOM object to get the login OK from the VB app**
obj2XMLDOM.Load Request
Dim LoginOK,str2ResultXML
LoginOK = obj2XMLDOM.SelectSingleNode("SOAP:Envelope/SOAP:Body/m:ImportOrders/LoginOK").Text
LoginOK =LoginOK & "ABDzf3"
'**Connects to a database and sends the login to a stored procedure to retrieve order data**
set RsImportLine = Server.CreateObject("ADODB.Recordset")
blahblah.........
'*A loop on the recordset builds a string with XML tags**
str2ResultXML = str2ResultXML & "<ligne>" & "<SAGEOrderDetailID>" & RsImportLine.Fields.Item("OrderID").value & "</SAGEOrderDetailID>"
BlahBlah......
str2ResultXML = str2ResultXML & "</ligne>"
%>

<%
set RsImportOrders =NOTHING
'**Setting the Response.Charset value to ISO doesn't help**
'Response.Charset="ISO-8859-1"
Response.Write str2ResultXML
%>







BORIS
Reply With Quote
  #2 (permalink)  
Old December 20th, 2003, 09:15 PM
Registered User
 
Join Date: Dec 2003
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by boris
 Hi,
I have a VB application which sends an XML file (a login) using SOAP to an ASP page. And then the ASP page checks the login, once done it returns a Text which the listening VB application loads to a DOMDocument.

My problem is : when the VB (client) App runs on Windows2000,
the XMLHTTP response.text method won't get the file correctly if it is encoded in ISO-8859-1.
There are question marks instead of accentued characters.

Everything works fine when the VB (client) App runs on Windows XP...

I have tried different regional settings with no result.

Any help will be greatly appreciated!!!
////////////////////////////////////////////////////////////////
VB app:
Dim obj2XMLHTTP As New MSXML.XMLHTTPRequest
    Dim str2MethodResultXML

    Dim strMethodPkg2 As String
           
           strMethodPkg2 = "<SOAP:Envelope xmlns:SOAP=""http://schemas.xmlsoap.org/soap/envelope/"">"
           strMethodPkg2 = strMethodPkg2 & "<SOAP:Header></SOAP:Header>"
           strMethodPkg2 = strMethodPkg2 & "<SOAP:Body><m:ImportOrders xmlns:m=""urn:soapserver/soap:AuthorizationModule"">"
           strMethodPkg2 = strMethodPkg2 & "<LoginOK>" & "MyLogin" & "</LoginOK>"
           strMethodPkg2 = strMethodPkg2 & "</m:ImportOrders></SOAP:Body></SOAP:Envelope>"
           obj2XMLHTTP.open "post", "http://SomeURL.asp", False

           obj2XMLHTTP.setRequestHeader "Content-Type", "text/xml"
               obj2XMLHTTP.setRequestHeader "SOAPAction", "soapserver/soap:AuthorizationModule#ImportOrders"

           obj2XMLHTTP.send strMethodPkg2
               
           str2MethodResultXML = obj2XMLHTTP.responseText
           xmldoc.async = False
           xmldoc.loadXML str2MethodResultXML
/////////////////////////////////////////////////////////////////
ASP Page:

<%Set obj2XMLDOM = Server.CreateObject("Microsoft.XMLDOM")

'**uses the obj2XMLDOM object to get the login OK from the VB app**
obj2XMLDOM.Load Request
Dim LoginOK,str2ResultXML
LoginOK = obj2XMLDOM.SelectSingleNode("SOAP:Envelope/SOAP:Body/m:ImportOrders/LoginOK").Text
LoginOK =LoginOK & "ABDzf3"
'**Connects to a database and sends the login to a stored procedure to retrieve order data**
set RsImportLine = Server.CreateObject("ADODB.Recordset")
blahblah.........
'*A loop on the recordset builds a string with XML tags**
str2ResultXML = str2ResultXML & "<ligne>" & "<SAGEOrderDetailID>" & RsImportLine.Fields.Item("OrderID").value & "</SAGEOrderDetailID>"  
BlahBlah......
str2ResultXML = str2ResultXML & "</ligne>"
%>

<%
set RsImportOrders =NOTHING
'**Setting the Response.Charset value to ISO doesn't help**
'Response.Charset="ISO-8859-1"
Response.Write str2ResultXML
%>
   






BORIS
Reply With Quote
  #3 (permalink)  
Old August 12th, 2004, 01:54 PM
Registered User
 
Join Date: Aug 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Boris,

Did you ever figure out the answer to this? I've been having the same problem for months now.

thanks!

Reply With Quote
  #4 (permalink)  
Old August 13th, 2004, 06:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Oh the joys of character encodings :D

If you're having problems like this, a general rule is to use as few character conversions as possible. The best way to do this is to avoid using VB/ASP string variables for your XML because that's one place the encoding could be changed.

Some basic facts which may help are:
- using DOM.xml always results in a UTF-16 encoding regardless of any encoding set in your PI
- using DOM.save respects the encoding set in your PI
- internally VB/ASP strings are COM BSTR, which are UTF-16 I believe
- XMLHTTP sends using UTF-8 by default

Looking at Boris's code, the things I would do differently are:
A. in the VB:
1. use a DOM document to construct the xml rather than building it using a string, and add a PI to the DOM which specifies the encoding you want to use.
2. when sending via XMLHTTP pass in the DOM doc to the send method (don't pass in the DOM.xml because this doesn't necessarily preserve encoding)
3. when receiving the XML back from the XMLHTTP send, use the responseXML property which will give you a DOM object directly

B. in the ASP
1. use a DOM document to construct the xml from the recordset, and add a PI to the DOM which specifies the encoding you want to use. (The easiest way to do this is to use the save method of the Recordset, specifying the format as XML and passing in the DOM doc as the target of the save - but, you will have to live with Microsoft's xml format if you do it this way.)
2. when sending the Response, use "DOM.save Response" as this preserves encoding. Do not use Response.Write DOM.xml as encoding conversions will be happening if you do this.

Having said all that, I'm surprised you're having problems with such a basic charset as iso-8859-1. A couple of questions for you:

- is there any particular reason it must be iso-8859-1? With these sorts of operations you'll do much better with UTF-8.
- are you absolutely certain that the chars which don't display are actually in the iso-8859-1 character set?
- can you give an example (character code) of some chars that don't display?

hth
Phil
Reply With Quote
  #5 (permalink)  
Old January 2nd, 2005, 11:23 AM
Registered User
 
Join Date: Jan 2005
Location: Stockholm, Stockholm, Sweden.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I faced the same problem myself and finally solved it. The encoding is corrupted when it is converted to a string with xmlhttp.responseText The solution is to use xmlhttp.responseBody instead and convert the binary data to a string using vbscript. See the code below:

<script language="vbscript" runat="server">
Function bts(data)
    'Converts binary data to string
    sOut = ""
    For i = 0 to UBound(data)
    sOut = sOut & chrw(ascw(chr(ascb(midb(data,i+1,1)))))
    Next
    bts=sOut
End Function
</script>

<%
//Using JavaScript ASP
var url="http://www.yourpage.com";
var conn = Server.CreateObject("Msxml2.XMLHTTP.3.0");
conn.Open("get", url, false);
conn.Send();
var htmltext=bts(conn.responseBody);
Response.Write(htmltext); //Writes with correct encoding!
%>
Reply With Quote
  #6 (permalink)  
Old January 15th, 2005, 11:56 PM
Registered User
 
Join Date: Jan 2005
Location: Lisbon, , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This tip worked great for me. I'd just like to point out that for people using compiled Visual Basic, you can use the built in StrConv function which is much faster than the custom bts function.


It would look like this:

Code:
htmltext = StrConv(conn.responseBody, vbUnicode)
Again, I think this only works in compiled visual basic, I believe the StrConv function is not available in scripting.

Reply With Quote
  #7 (permalink)  
Old June 14th, 2006, 09:24 AM
Registered User
 
Join Date: Jun 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ratna_ain
Default

I have a problem.I hope someone can help me to solve it.
In Database i hava a field that contains thai character.
If i want to view the content of that field in web i set
<meta http-equiv="Content-Type" content="text/html;charset=TIS-620"> and the thai character will show correctly
But, i want to make that page become an auto refresh page, so i use ajax, and the thai character become "??????".:( Anybody know how to solve this problem?
Thanks u before



Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Encoding & xmlhttp object rajn ASP.NET 1.0 and 1.1 Professional 1 April 22nd, 2007 08:56 AM
PROBLEMS! Posting Form Fields with XMLHTTP kevorkian Classic ASP XML 2 December 7th, 2006 03:43 PM
xmlhttp matteoallorg RSS and Atom 0 July 12th, 2005 01:37 PM
xmlhttp help ojaynet RSS and Atom 2 April 8th, 2005 05:13 PM
XMLHTTP ffbalota Classic ASP XML 7 October 7th, 2003 06:11 PM



All times are GMT -4. The time now is 05:23 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.