|
Joined: Jul 2006
Posts: 4,150
Hoopy frood
|
OP
Hoopy frood
Joined: Jul 2006
Posts: 4,150 |
In this thread, kap tries to call the method 'load' of the object MSXML2.DOMDocument.6.0, described here: if ((!$com(XSL, load, 1, bstr, %xslt)) || ($comerr)) handle error This code is not correct because the load method is not for literal string, rather for url, or others things. Am i missing something, or shouldn't that code be setting $comerr all the time, rather than none of the time, as it is currently doing?
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Dec 2002
Posts: 5,421
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 5,421 |
Thanks for your bug report. I have not been able to run this script as it reports "Can't load XML information". That said, if the COM call fails, it should always set $comerr.
|
|
|
|
Joined: Feb 2015
Posts: 138
Vogon poet
|
Vogon poet
Joined: Feb 2015
Posts: 138 |
Thanks for your bug report. I have not been able to run this script as it reports "Can't load XML information". That said, if the COM call fails, it should always set $comerr. I think you get that error message because I rescinded that API key. Here's the same block of code, but with a (now) working key. As you can see, Khaled, Ouims is right in pointing out that something is not working as expected? It's not detecting the error in the objStylesheet alias...
alias -l url_encode return $regsubex($1, /([\W\s])/Sg, $iif(\t == $chr(32), +, $+(%, $base($asc(\t), 10, 16, 2))))
alias objStylesheet {
var %error, %xslt <?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:output method="text" indent="no" omit-xml-declaration="yes" /><xsl:template match="/">City: <xsl:value-of select="/current/city/@name" /> - Country: <xsl:value-of select="/current/city/country" /> - Temperature: <xsl:value-of select="/current/temperature/@value" /><xsl:value-of select="/current/temperature/@unit" /></xsl:template></xsl:stylesheet>
if ($com(XSL)) .comclose XSL
.comopen XSL MSXML2.DOMDocument.6.0
if ((!$com(XSL, async, 4, bool, false)) || ($comerr)) %error = Can't set async property on obj XSL
if ((!$com(XSL, load, 1, bstr, %xslt)) || ($comerr)) %error = Can't load stylesheet information from ' $+ %xslt $+ '
:error
if ($error) %error = $v1 | reseterror
if (%error) echo $color(info text) -ag %error
}
alias objWeather {
var %error, %loc $url_encode($1-)
var %api_url http://api.openweathermap.org/data/2.5/weather
; Please specify your own api key below
var %api_key 45ee6174666139e777e1d0fbc890137e
; You can specify units: `imperial`, `kelvin` and `metric`
var %units metric
var %page $+(%api_url,?q=,%loc,&units=,%units,&mode=xml,&appid=,%api_key)
if ($com(XML)) .comclose XML
.comopen XML MSXML2.DOMDocument.6.0
if ((!$com(XML, async, 4, bool, false)) || ($comerr)) %error = Can't set async property on obj XML
if ((!$com(XML, load, 1, bstr, %page)) || ($comerr)) %error = Can't load XML information from ' $+ %page $+ '
:error
if ($error) %error = $v1 | reseterror
if (%error) echo $color(info text) -ag %error
}
alias t1 {
objStylesheet
objWeather Vlissingen,nl
if ($com(XML, transformNode, 1, dispatch, XSL)) {
echo -ag Succeeded - $com(XML).result
}
}
Last edited by kap; 06/09/20 12:34 PM.
GNU Terry Pratchett - Looking for a mIRC help channel -> Check #mircscripting @ irc.swiftirc.net
|
|
|
|
Joined: Dec 2002
Posts: 5,421
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 5,421 |
Your first step should be to remove the $com() call from the /if statement, and assign its result to a variable, eg. var %result = $com(). You can then /echo result: %result comerr: $comerr afer the $com() call to see whether it is succeeding or failing. If the value returned by $com() is 1, this means that the call succeeded.
|
|
|
|
Joined: Apr 2010
Posts: 969
Hoopy frood
|
Hoopy frood
Joined: Apr 2010
Posts: 969 |
[Msxml2.DOMDocument.6.0].load() does not report an error for non-url string arguments. It returns a boolean value if the load was successful or not. If loading was not successful it returns false so you simply need to check against $com(XSL).result after the call to detect a load failure: if (!$com(XSL, load, 1, bstr, %xstl) || $comerr) {
; com related error
}
elseif (!$com(XSL).result) {
; load failed; you can dispatch parseError and check it's .reason property to get a plain text message as to why the load failed
} I know it may seem like it would throw an error for a non-url input due to the page linked below mentioning E_INVALIDARGS but that error is only returned if the input type of load() is not of an applicable type .load()"Return Values Boolean. Returns True if the load succeeded; False if the load failed." "xmlSource An indicator of the source XML to parse. This may be an URL (String/BSTR), a Request object (in an ASP page), an IStream, SAFEARRAY of bytes (VT_ARRAY|VT_UI1), a DOMDocument object, or any object that supports IStream, ISequentialStream, or IPersistStream." parseError membersIn short this is not a bug in mIRC, but rather scripter error.
Last edited by FroggieDaFrog; 06/09/20 02:35 PM. Reason: grammar
|
|
|
|
Joined: Feb 2015
Posts: 138
Vogon poet
|
Vogon poet
Joined: Feb 2015
Posts: 138 |
In short this is not a bug in mIRC, but rather scripter error. Alright, cheers! Thank you for the information/break down SReject. :-)
GNU Terry Pratchett - Looking for a mIRC help channel -> Check #mircscripting @ irc.swiftirc.net
|
|
|
|
|