Solved

Reading bytes from a "SAFEARRAY" in VBscript

Posted on 2002-04-08
13
565 Views
Last Modified: 2008-03-04
I have an IE6 MS XML 3.0 DOM script that is supposed to get a "SAFEARRAY" of raw bytes from a server.  IsArray() returns True, Ubound(x) returns 186. But how do I access the value of individual bytes in this supposed array?

http://heima.olivant.fo/~styrheim/xml/nummar/test.html
0
Comment
Question by:janegil
  • 5
  • 4
  • 4
13 Comments
 
LVL 15

Expert Comment

by:robbert
Comment Utility
You won't be able to access a Byte() array in VBScript. VBScript only recognizes Variant arrays which items are of datatype Variant, too.

Anyway. Probably, you just want to retrieve the XML, and want to display the iacute, correctly.

Weeeeellll, I can tell you how -- but not why, and not for a B grade... Deal?
0
 
LVL 1

Author Comment

by:janegil
Comment Utility
Indeed, I just want the XML. The catch is, I want the XML from a page with MIME type text/vnd.wap.wml and ISO-8859-1.

(If the MIME is text/xml, OR the encoding is UTF-8, there is no problem.)

http://heima.olivant.fo/~styrheim/xml/nummar/no2.html 'proves' that it can't be done.

I also have a posting at http://www.experts-exchange.com/xml/Q.20283930;jsessionid=02AF9D420FEBFF28305A97FCBA8A1882.html

So yes, if you can give me IE6 code that will extract the XML from acute.wml, you have a deal. Opera or Mozilla browsers would be most welcome substitutes, but then I also need to know how to apply an XSL transformation.



0
 
LVL 15

Expert Comment

by:robbert
Comment Utility
janegil,
this is an open book for me, too, and there are many open questions related to encodings. I too, after a long time of searching, didn't find a "rule-set", or W3C recommendations, or whatever, that I can apply.

Fact is, it works when you replace the iacute character by "í". "237" is the integer representation of that character:
MsgBox Asc("í")
MsgBox Chr(Asc("í"))

So, there are two possibilities:
1. Change the code of the XML document:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
     <card>
          <p>&#237;</p>
     </card>
</wml>

Or 2., replace the offending characters after you received it, and before you are evaluating the string as XML.
Well, I tried anything but was not able to find (and replace) the offending characters.

<SCRIPT TYPE="text/javascript" EVENT="onload" FOR="window">
     var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
     wapurl = "http://heima.olivant.fo/~styrheim/xml/nummar/iacute.wml?";
     xmlhttp.Open("GET", wapurl, false);
     xmlhttp.Send();          
     
     var strXML = xmlhttp.responseText
     strXML = DecodeString(strXML)
     
     var objXML = new ActiveXObject("MSXML2.DOMDocument")
     if (!objXML.loadXML(strXML))
          alert("parseerror: " + objXML.parseError.reason);
     alert("XML: " + objXML.xml)
</SCRIPT>
<script language="vbscript">
     Function DecodeString(ByVal strString)
          '#### this will not detect iacute
          msgbox "InStr: " & instr(1, strstring, Chr(237))
         
          strString = Replace(strString, Chr(237), "&#237;")
          DecodeString = strString
     End Function
</script>

I'm sorry. Here is what I have, and that's no solution. You can replace those offending characters before sending them but I cannot find them once their sent. Additionally, I don't know of specifications when to use which characters.

I'm sorry. Please do not grade this. I never found any answer to such questions.
0
 
LVL 1

Author Comment

by:janegil
Comment Utility
In principle, it might be doable, by searching for all UNICODE characters whose UTF-8 representation begins with tyhe iacute byte. But they are too many combinations, ands some ISO-8859-1 byte sequences are probably not valid UTF-8 at all.

What then? Wait for IE7? Look at Mozilla DOM?
0
 
LVL 23

Expert Comment

by:b1xml2
Comment Utility
workaround
==========
<html>
<head>
<title>Load External Sources</title>
<script TYPE="text/javascript">
function testrun(wapurl) {
     var source = new ActiveXObject("Msxml2.DOMDocument.3.0");
     source.resolveExternals = source.validateOnParse = source.async = false;
     var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
     xmlhttp.Open("GET", wapurl, false);
     xmlhttp.Send();
     source.load(xmlhttp.responseBody);
     alert(source.xml);    
}
         
function test() {          
     testrun("http://wap.pyweb.com/ch?pyid=160f4d.01&Eftirnavn=hans&Fornavn=hansen&Leita=+Leita+");
     testrun("http://landsbank.fo/test/hansen.xml");
     testrun("http://landsbank.fo/test/hansen.wml");
}
</script>
</head>
<body>The workaround
<p><a href="javascript:test();">TEST the SCRIPT</a></p></body>
</html>
0
 
LVL 23

Accepted Solution

by:
b1xml2 earned 200 total points
Comment Utility
you load the responseBody straight into the XML Object.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 23

Expert Comment

by:b1xml2
Comment Utility
correct me if I am wrong, but I believe I hit the jackpot =P~~
0
 
LVL 23

Expert Comment

by:b1xml2
Comment Utility
by the way, although the DOM.xml property does not show the encoding, tests on server-side indicate that the encoding is as per the XML Document and thus is "ISO-8859-1". If you create a HTA and save the XML on the client-side, you will see the encoding attribute in the xml pi.
0
 
LVL 23

Expert Comment

by:b1xml2
Comment Utility
Notes
=====
1. To guarantee correct loading of XML Documents, load the responseBody =)
0
 
LVL 1

Author Comment

by:janegil
Comment Utility
Well. I really don't care what encoding is used, as long as it works, and as long as my transformation result will use an encoding the IE6 will be able to display. UTF-16, UTF-8 and ISO-8859-1 are equally acceptable. Even ASCII with character entities would do.
0
 
LVL 15

Expert Comment

by:robbert
Comment Utility
Meanwhile, I got it, too (at least partially).
There are two ways to transfer XML: a) Text, b) Stream (load() vs. loadXML() method, ADODB.Stream, File I/O, ...).
loadXML() reverts the encoding to (I believe) UTF-16 (which is MSXML's default encoding).
Here's some heuristic documentation ;-) - http://www9.brinkster.com/robbert/v20010810181946.zip
0
 
LVL 15

Expert Comment

by:robbert
Comment Utility
Oops. They changed their policies for zips. Use http://www9.brinkster.com/robbert/encoding.htm
0
 
LVL 1

Author Comment

by:janegil
Comment Utility
The working result at http://heima.olivant.fo/~styrheim/nummar.html

It is slow, and seem even slower than it is, because all rendering is delayed until the script has finished. Maybe I should try some setTimeoyt() sorcery?
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now