janegil
asked on
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
http://heima.olivant.fo/~styrheim/xml/nummar/test.html
ASKER
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 https://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.
(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 https://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.
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>í</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.XMLH TTP.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.DOMD ocument")
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), "í")
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.
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>í</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.XMLH
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.DOMD
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), "í")
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.
ASKER
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?
What then? Wait for IE7? Look at Mozilla DOM?
workaround
==========
<html>
<head>
<title>Load External Sources</title>
<script TYPE="text/javascript">
function testrun(wapurl) {
var source = new ActiveXObject("Msxml2.DOMD ocument.3. 0");
source.resolveExternals = source.validateOnParse = source.async = false;
var xmlhttp = new ActiveXObject("Msxml2.XMLH TTP.3.0");
xmlhttp.Open("GET", wapurl, false);
xmlhttp.Send();
source.load(xmlhttp.respon seBody);
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>
==========
<html>
<head>
<title>Load External Sources</title>
<script TYPE="text/javascript">
function testrun(wapurl) {
var source = new ActiveXObject("Msxml2.DOMD
source.resolveExternals = source.validateOnParse = source.async = false;
var xmlhttp = new ActiveXObject("Msxml2.XMLH
xmlhttp.Open("GET", wapurl, false);
xmlhttp.Send();
source.load(xmlhttp.respon
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();">
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
correct me if I am wrong, but I believe I hit the jackpot =P~~
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.
Notes
=====
1. To guarantee correct loading of XML Documents, load the responseBody =)
=====
1. To guarantee correct loading of XML Documents, load the responseBody =)
ASKER
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.
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
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
Oops. They changed their policies for zips. Use http://www9.brinkster.com/robbert/encoding.htm
ASKER
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?
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?
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?