Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 596
  • Last Modified:

Reading bytes from a "SAFEARRAY" in VBscript

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
janegil
Asked:
janegil
  • 5
  • 4
  • 4
1 Solution
 
robbertCommented:
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
 
janegilAuthor Commented:
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
 
robbertCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
janegilAuthor Commented:
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
 
b1xml2Commented:
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
 
b1xml2Commented:
you load the responseBody straight into the XML Object.
0
 
b1xml2Commented:
correct me if I am wrong, but I believe I hit the jackpot =P~~
0
 
b1xml2Commented:
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
 
b1xml2Commented:
Notes
=====
1. To guarantee correct loading of XML Documents, load the responseBody =)
0
 
janegilAuthor Commented:
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
 
robbertCommented:
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
 
robbertCommented:
Oops. They changed their policies for zips. Use http://www9.brinkster.com/robbert/encoding.htm
0
 
janegilAuthor Commented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now