Category: Tools

  • Format any XML (windows)

    With this blog post, it’s possible to format any xml you’ve selected.
    It will take about 5 minutes to get this working, a couple of manual steps are necessary.
    These are the tools being used:

    Steps to get it working: (All steps are necessary!)

    1. First install AutoHotKey_L and start it, you’ll see the logo if it’s running: AutoHotKey logo
    2. Create a folder on your Hard Drive called “C:\autohotkey”
    3. Create a file “tidycfg.ini” in the location “C:\autohotkey\tidycfg.ini” with the following contents:
      1. [Clean Indent XML]
        input-xml: yes
        bare:no
        clean:no
        fix-bad-comments:no
        fix-backslash:no
        indent:yes
        indent-attributes:no
        indent-spaces:4
        char-encoding:raw
        replace-color:no
        wrap:0
        wrap-asp:no
        wrap-jste:no
        wrap-php:no
        write-back:yes
    4. Place tidy.exe in the location C:\autohotkey
    5. Create a file called “autohotkey.ahk” in C:\autohotkey with the following contents:
      1. #x::
        sleep 50
        Send ^c
        ClipWait
        clipboard = %clipboard%
        FileDelete, C:\autohotkey\format_with_tidy.xml
        FileAppend, %clipboard%, C:\autohotkey\format_with_tidy.xml
        sleep 50
        RunWait, %comspec% /c C:\autohotkey\tidy.exe -config C:\autohotkey\tidycfg.ini C:\autohotkey\format_with_tidy.xml
        clipboard =
        FileRead, clipboard, C:\autohotkey\format_with_tidy.xml
        Return
    6. Doubleclick the file “autohotkey.ahk” in C:\autohotkey
    7. Select unformatted xml and press [ WINKEY+X ]
    8. The formatted xml is now in your clipboard and can be pasted anywhere.

    Extra information:

    These are the steps what is happening in the autohotkey file:

    1. Configure the keyboard shortcut (# = winkey, x = x-key)
    2. Wait 50 milliseconds
    3. Send the ctrl-c with keyboard combination ^c ( ^ = ctrl, c = c-key)
    4. Wait until the clipboard is filled
    5. remove all formatting from the clipboard
    6. Delete the temporary file (if present)
    7. Paste the clipboard contents in the temporary file
    8. Wait 50 milliseconds
    9. Run tidy.exe on the temporary file with the configuration settings
    10. empty the clipboard
    11. Paste the contents of the temporary file in the clipboard
    12. End script
  • Validate XML to XSD with XMLLINT on CLI

    Awesome-ness!!
    I was looking for a nice tool to validate my XML messages against an XML Schema, when I ran into this command where you can really easily validate on the command line. That’s really cool since we’re becoming CLI ninjas anyway!
    Update: This also works on Windows with this little gem.
    The command is as follows:

    xmllint --noout --schema schema.xsd ./message.xml

    Which delivered the following output:

    joris@jorislatitude:~/workspaces/_examples/XSD$ xmllint --noout --schema sample_schema.xsd ./messageone.xml
    ./messageone.xml:2: element S_UNB: Schemas validity error : Element 'S_UNB': This element is not expected. Expected is ( INSDES ).
    ./messageone.xml fails to validate

    As shown in above message, my example failed to validate, which is what I suspected, but now I can send my integration partner a better and really precise explanation! As said above: Awesomeness! 🙂

  • Fake SMTP server! Great for testing email / SMTP!

    Often in projects you will be asked to send an email when an error occurs, or as a part of the functional process.
    Unfortunatly it is sometimes a bit cumbersome to make sure you are not sending mail to real email addresses.. I’ve recently found a nice solution for this problem: a fake SMTP server!
    This way, you only have to change the IP address on your SMTP endpoint instead of checking every emailaddress or disabling all the actual email functionality.
     
    The application is called “FakeSMTP” (What’s in a name?) 🙂 and can be found through this link: http://nilhcem.github.com/FakeSMTP/index.html

    Screenshot - FakeSMTP Main screen
    Screenshot – FakeSMTP Main screen

    As you can see in the screenshot, the program runs on the port you assign to it, acting as an email server with all the correct responses, with the only difference that it does not actually send out the emails. The emails are stored in a folder which you can specify. You can also double click on the message row in the program to open the email in your email client (in my case Outlook) which worked great for testing purposes.
    I was quite pleased when I found this solution :-), hope it will help you guys too!

  • SQL Developer, Comma's before columns!

    I’ve been using SQL Developer a lot lately for data analysis and I’ve been getting used to the auto formatting to easily create well readable code out of my garbled-“I’m in a hurry”-SQL-mess.
    This works like a charm, except for the comma’s which kept showing up at the end of the column names after the auto formatting, a small annoyance which is easily solved with this trick.
    This is the default auto-formatting which is used by SQL Developer:

    SELECT t1.column1,
     t1.column2,
     t2.column3
    FROM table1 t1
    JOIN table2 t2
    ON t1.value1 = t2.value2;

    You can change this behaviour by accessing the following settings:
    Tools -> Preferences -> Database -> SQL Formatting -> Oracle Formatting -> Press button “Edit”
    In the Oracle Formatting window: Line-breaks -> Select “Before comma” and deselect “After comma”

     
    After this trick, the default formatting will have this code as a result:

    SELECT t1.column1
    , t1.column2
    , t2.column3
    FROM table1 t1
    JOIN table2 t2
    ON t1.value1 = t2.value2;
     

    Happy querying! 🙂