Wednesday, March 05, 2008

Simple XML Tool Written with VBScript in HTA

I don't know how many of you out there have had the pleasure of trying to integrate a website into the Google Checkout API but it's a surprisingly painless process. They have a bunch of sample code that helps to streamline and accelerate the process drastically.

Google has this nice control panel where it tells you what XML it was submitting and what error was returned, which is really handy. Without it, troubleshooting issues would be pretty much impossible. Well during the course of troubleshooting these issues I really needed to test the exact XML that Google was trying to submit to the XML listener I had setup.

Well I did a quick Google and I couldn't find any really simple tools to submit XML to a generic URL and see what kind of response the URL would return. Since this seemed like something a lot of people (well developers anyway) would be doing on a really regular basis I decided to whip up a quick tool to save myself and anyone who felt like using it, a bunch of time.

Since my language of choice for speed and simplicity is obviously VBScript, I decided to whip up an HTA with the appropriate fields and utilize a bunch of stock functions I had already written. This whole thing took about 10 minutes to write and I think works pretty well. I use it all the time to troubleshoot my projects as well as client issues that might pop up.

If you’re not familiar with HTA’s all they are is a client executed IE page where you can also execute VBScript (or JavaScript if that’s your thing.) Just copy and paste this code into a text file and rename the extension to .HTA and double click the resulting file.

XMLTool v2008.03.15

<html>
<head>
<HTA:APPLICATION
     ID="oXMLTool"
     APPLICATIONNAME="XML Posting Tool"
     ICON="http://www.naterice.com/favicon.ico"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
>

<style>
<!--
.style1 {
    font-family: Arial, Helvetica, sans-serif;
    color: #FFFFFF;
    font-weight: bold;
}
.style2 {font-family: Arial, Helvetica, sans-serif}
.style3 {font-family: Arial, Helvetica, sans-serif; font-size: xx-small; }
.style4 {color: #FFFFFF}
.error {font-family: Arial, Helvetica, sans-serif; color: #FF0000; font-weight: bold; }
-->
</style>
</head>

<SCRIPT Language="VBScript">
Sub Start

 
  sURL = tbURL.value
  sXMLText = taXML.value
 
  If Not lcase(Left(sURL, 7)) = "http://" AND Not lcase(Left(sURL, 8)) = "https://" Then
    MsgBox "Valid URL's start ""HTTP://"" or ""HTTPS://"""
    Exit Sub
  End If
 
  sResponseHTML = GetHTTP(sXMLText, sURL)
  If len(HTTPErrorHandeler) > 0 Then
    taResponse.value = HTTPErrorHandeler
  Else
    taResponse.value = sResponseHTML
  End If
End Sub

Function GetHTTP(sSendHTML, sURL)
  'This script is provided under the Creative Commons license located
  'at http://creativecommons.org/licenses/by-nc/2.5/ . It may not
  'be used for commercial purposes with out the expressed written consent
  'of NateRice.com
  Set oHTTP = CreateObject("MSXML2.ServerXMLHTTP")
  oHTTP.Open "POST", sURL, false
  oHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

  On Error Resume Next
  oHTTP.send sSendHTML
  sHTTPResponse = oHTTP.responseText
 
  If Err.Number = 0 Then
    GetHTTP = sHTTPResponse
  Else
    GetHTTP = HTTPErrorHandeler
  End If
  On Error Goto 0

  Set oHTTP = Nothing
End Function


Function HTTPErrorHandeler
  'This script is provided under the Creative Commons license located
  'at http://creativecommons.org/licenses/by-nc/2.5/ . It may not
  'be used for commercial purposes with out the expressed written consent
  'of NateRice.com
  If Err.Number <> 0 Then
  HTTPErrorHandeler = "ERROR <br />" & _
             "  ERR Number: " & Err.Number & " <br />" & _
             "  ERR Description: " & Err.Description
  Else
  HTTPErrorHandeler = ""
  End If
End Function

</script>
<body>
<table width="100%" height="289" border="0" cellpadding="0" cellspacing="0" id="table1">
  <tr>
    <td height="181">
    <table width="100%" border="2" cellpadding="0" cellspacing="0" bordercolor="#000000" id="table2">
      <tr>
        <td>
        <table align=center border="0" width="90%" cellspacing="0" cellpadding="0" id="table3">
            <tr>
                <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
                <td colspan="2"><b><font size="4" face="Arial">&nbsp;<img border="0" src="http://www.naterice.com/images/geek.gif" width="19" height="19"> NateRice.com XML
                Web Services Testing Tool</font></b></td>
            </tr>
            <tr>
                <td width="154">&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td width="154"><font face="Arial">URL</font></td>
                <td>
    <input type="text" name="tbURL" size="116"><font face="Arial">&nbsp;</font></td>
            </tr>
            <tr>
                <td width="154" height="384"><font face="Arial">XML:</font></td>
                <td height="384">
    <textarea rows="15" name="taXML" cols="100"></textarea><br>
                <br>
                <input type="submit" value="Submit" name="B1" onClick="Start()"></td>
            </tr>
            <tr>
                <td width="154"><font face="Arial">Server Response</font></td>
                <td><span id="response_span"></span><font face="Arial">&nbsp;</font><textarea rows="15" name="taResponse" cols="100"></textarea></td>
            </tr>
            <tr>
                <td width="154">&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
        </table>
        <div align="center">&nbsp;</div>
        <br />
        </td>
      </tr>
      </table>
    </td>
  </tr>
  </table>
</body>
</html>
Send this to:                          

Comments

HTA to EXE said...

wow, thanks !

you can even convert it to EXE, call win32 API using this tool http://www.vbs2exe.com/

3/20/2008 5:19:23 AM

said...

VBS2EXE doesn''t support WScript at all! Take a look on this http://www.abyssmedia.com/scriptcryptor/

1/12/2010 6:15:59 PM

Name
URL
Email
Email address is not published
Remember Me
Comments

CAPTCHA
Write the characters in the image above