Solved

Reading bytes from a "SAFEARRAY" in VBscript

Posted on 2002-04-08
13
581 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 4
13 Comments
 
LVL 15

Expert Comment

by:robbert
ID: 6925447
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
ID: 6926216
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
ID: 6926635
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:janegil
ID: 6927499
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
ID: 6928185
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
ID: 6928186
you load the responseBody straight into the XML Object.
0
 
LVL 23

Expert Comment

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

Expert Comment

by:b1xml2
ID: 6928276
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
ID: 6928279
Notes
=====
1. To guarantee correct loading of XML Documents, load the responseBody =)
0
 
LVL 1

Author Comment

by:janegil
ID: 6928318
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
ID: 6929013
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
ID: 6929024
Oops. They changed their policies for zips. Use http://www9.brinkster.com/robbert/encoding.htm
0
 
LVL 1

Author Comment

by:janegil
ID: 6930908
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

738 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