Originally Posted by Khaled
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...

Code
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