Improve company productivity with a Business Account.Sign Up

x
?
Solved

Reading bytes from a "SAFEARRAY" in VBscript

Posted on 2002-04-08
13
Medium Priority
?
605 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
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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 800 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

607 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