Working With XML/XSLT, JSON, And PHP

So, this tale, which for your sake I will attempt to make brief, is typical of my experiences in web development. As one of my old bosses used to say (and I’m paraphrasing), “if there’s a hard way to do it, you’ll try that way first.”

To begin, I have as my personal homepage, a calendar page that is scripted with PHP and MySQL. The calendar not only displays date information, but also displays things like birthdays, Sun and Moon information, bills, and a to-do list. As I constantly visit weather sites I decided it was time to bring the weather information to my calendar. Searching an API link site I found that the NOAA provides just what I needed: NOAA Weather API. While it was fun setting up the SOAP call, the resulting information (returned) was in XML format. Not the biggest fan of XML, but it’s what we’re given to work with in this situation.

Fast forward through scripting the SOAP call, caching data locally for X amount of hours (NOAA would appreciate not being queried over once per hour), writing the initial XSL for XSLT, and wrapping it as an object for display in my calendar. Everything seemed to be fine till I decided to look at my calendar with my smart phone. Turns out the smart phone (an old one) running Android 2.2.2 wouldn’t translate the XML in it’s built in browser. I have no idea if newer phones will deal with XML (maybe with a different browser?), but that didn’t matter to me, it has to run everywhere.

Researching the subject someone pointed out that whenever possible all XML transformation should be done server-side. I understood what he was talking about, browser compatibility issues being the bane of every web developer, but that adds to server-side load, not to mention the fact that if done server-side, there’s not much advantage of using XML in the first place (for information transmission). One of the perks (perquisites) of transmitting data in XML format is being able to display it in virtually any manner with a simple change of XSL (because all of the data is already there).

Okay, so now I’ve set out to do the transformation server-side. Great. Not that big a deal. The one sticking point was that I needed to include the following line (which took some research):

<xsl:output method="html"></xsl:output>

That and a couple other changes to my PHP script, and everything was being delivered as (X)HTML to the browser. Even works on my cell phone. Great, score one for me!

A while goes by and I decide to change the SOAP call to get 12 hour data as opposed to 24 hour data. That would help to narrow down when rain, for example, was to be expected. This turned out to be a lot more work once I jumped back into the XSL(T). You see, the data is presented in 12 hour blocks, sequentially, in one section, day – night – day – night, etc., and grouped in another, high temperatures (group one) and low temperatures (group two). While this may not have presented a problem to someone more adept with XSL, it was a stumbling block for me, to say the least. After beating my head against the wall for some time, not sure how much exactly, I did get it to work … mostly. And to be sure, had I not decided it simply was not worth my effort, I would have hammered out the remaining issues. However, it suddenly dawned on me, to heck with XML, convert it to an array, and then I can do whatever I want in PHP.

Initial searches turned up suggestions to turn it into JSON. I was okay with that. I mean, javascript is cool, and besides from there I could convert it to an array if I still wanted. Unfortunately, some of the data I needed was in attributes of the XML, which simple code, like below, would not get. Mostly worked.

$xml = simplexml_load_string($xml_string);
$json = json_encode($xml);
$array = json_decode($json,TRUE);

Further research and several failed attempts (read that as code did not work) and I happened across a PHP class at: XML To Array With PHP which works. Include the class and add the following, and I was off to the races.

$weatherArr = new simpleXml2Array($weatherXML, null);
$arr = $weatherArr->arr['data'][0]['parameters'][0]['content'];

$arr now held everything I needed and could be dealt with in a straight forward fashion. Well, to be fair, straight forward to me.

tldr; XML is overly complicated and is not as useful as was originally intended (my opinion). XSLT should be done server-side. Better yet, convert XML to JSON or an array (for PHP consumption) and life will be much easier.

Posted in PHP | Tagged , , , , , , , , , , , , , , | Leave a comment

Rainy Day Fun With Photoshop

So, it’s raining off and on, and taking a moment’s break from my usual tasks I decided to do something different. Looking at the weather map to see the rain occurring in the area always shows blank corridors. Obviously, these blank areas are either deliberate or caused by obstruction (radar being line of sight and all). Anyway, a screengrab and a couple stroked paths later and I have this:

Map of Long Island and parts of New York, Connecticut, showing cloud cover as depicted by radar

Triangulating radar station location using Photoshop

A quick look at google maps and the location appears to be the NOAA station here:

Closeup map view of Long Island centering around NOAA

NOAA as per Google Maps

Fun stuff!

Posted in Fun With Photoshop | Tagged , , | Leave a comment

Arrival At Pluto

New Horizons is scheduled to arrive at the PLANET Pluto (don’t give me any of that dwarf or minor crap) on:

select DATE_ADD(date(‘2015-06-02’), INTERVAL 42 DAY) as ‘Arrival at Pluto’;

Kind of sad that I thought it would be easier to write the query than count the days manually, huh?

WordPress likes to help by adding weird apostrophes, so:

select DATE_ADD(date('2015-06-02'), INTERVAL 42 DAY) as 'Arrival at Pluto';

This yields 2015-07-14

Posted in MySQL | Tagged , , , , , | Leave a comment

Plumber Truck Graphic

Today a plumber’s truck stopped at a neighbor’s house. The graphic on the back door sent my mind into overtime (as per usual). Here is the original:

A man sitting on a toilet with a smokestack coming out of the back

Plumber Truck Graphic – Original

Here is one of the ideas that popped into my head:

Man sitting on toilet with cat on head, smokestack coming out of back of toilet

Plumber Truck Graphic – Photoshopped

I had other ideas, but I haven’t gotten around to making them yet. Photoshop, you gotta love it!

Posted in Fun With Photoshop | Tagged , , | Leave a comment

The Divergent Series: Insurgent Review

I finally got around to seeing the movie today (probably one of the last to see it at the theater). To be honest, it surprised me that it was in the theaters so long. I guess it struck a cord with some people. I guess.

Anyway, I could make a long list of issues I had with the movie (the script), but I’ve condensed it down to this:

  • Nothing against the script in this one. Just thought it was worth noting. Anyway, Leonardo can finally rest in peace as Kate didn’t live long enough (this time) to throw any more diamonds into the ocean. Score one for the men!
  • The smart ones (erudites), really? How smart can they be to let the divergent’s brother into the control room.
  • The smart ones, again. Letting the conniving dauntless into the control room? If the movie had run for another 15 minutes, I’m sure he would have flipped sides again.
  • Who didn’t see the “let’s get intimate so I can escape while you’re sleeping” scene coming? Talk about predictable (as well as stereotypical).

Seriously, did the person that wrote this just give up or go missing (thereby forcing the movie execs to use a homeless person to finish writing the script)?

In spite of my gripes (and there are more that I shan’t list), I enjoyed the movie. Shouldn’t win any awards, but entertaining.

Posted in Movie Reviews | Tagged , | Leave a comment

Having Conversations With Javascript

Have you ever wanted wanted to animate inanimate objects? I think we all have. Well, that’s a lot of work. A cheat that you can employ, however, is relatively easy with javascript and or jquery. No, I’m not talking about jquery’s animate function, which moves an image across the screen a certain distance on an event. To be sure, that could be used additionally. Btw, that’s one of the ways that I played with to animate Chuckman flying (similar to what you see at the top of this blog).

Maybe I should define what I mean by animation? In this instance, I am talking about the illusion of a conversation taking place between two snails. To better understand, click here. The default conversation that displays at that link can be changed. Click here to see a different conversation, or click here for yet another.

If you examine the links, you should observe a pattern. First, you need the base url. In this case that’s That needs to be followed by ?converse=. Then enter a command separated by a ^ from the parameter to be passed in. That’s pretty much it. Note: This script as yet is not bullet proof, meaning you can make it fail miserably. As this was just a fun project for me I may continue working on it, but no promises.

Commands that are currently present:

  • dImg – short for display image
  • dTxt – short for display text

Images available:

  • im1 – short for image one, which is the bubble that appears to issue forth from the left snail
  • im2 – short for image two, which is the bubble that appears to issue forth from the right snail
  • im3 – short for image three (the background image, calling this is a fun way to show the fragility of the script)

Format for use is command^parameter^command^parameter, etc., so dImg^im1^dTxt^Say something

In the above example we call the function dImg and pass it im1 (dImg(im1)) which overlays the bubble on the base image. We then call dTxt and pass it ‘Say something’ which prints ‘Say something’ over the bubble. Note: Don’t worry about the %20’s if you’re looking at the link. Percent 20 (and the likes) is just a web browser’s way of keeping spaces out of a url (link). Your link will work with spaces, and if you copy and paste it somewhere, you may find that %20’s mysteriously showed up on their own.

The script is commented, so if you want to see the inner workings, just look at the page source.

Things on my to do list include:

  • add a dynamically generated form for image/text addition
  • add character limit to conversation blurbs
  • add parsing and overriding of timing
  • add start/stop
  • maybe add navigation/image jumping

Have fun talking to yourself, I mean making the snails talk. =)

Note: It should be obvious that different functions could be written in the same way, allowing for instance, sound files to be played in conjunction with the images. Very interesting!

Posted in jQuery | Tagged , , , | Leave a comment

Japanese Transistor Radio

Remember when portable radios (A.M. radio) were the size of a large boom box and used half a dozen "D" batteries and or a lantern battery (a large, heavy, rectangular battery)? Okay, that might be a slight exaggeration. Then, one day came the Japanese transistor radio (with almost the same aural quality as the monster described above), which fit into the palm of your hand and ran on a 9 volt battery.

On that note:
Before the advent of transistors, tubes were the discrete diodes, triodes, etc., that did the rectifying, amplifying, etc. Here’s a link to a very cool video about a craftsman making some tubes, Click here to see video. So you’re aware, the video did not work in my Firefox browser, so I had to use Interpig Exploder. If you can read french, here is some documentation, Click here to find documentation.

Posted in Remember When | Tagged , , , | Leave a comment

Graphing With Flot

I was working on one of my personal projects, graphing data with PHP, when I ran into a wall. Sure, with PHP, you can get all your data (in the words of some famous poet: database, oh database, how do I query thee?), parse and arrange you data, and even display it graphically (via an image or indirectly through export to spreadsheet), but there’s no interactivity. Well, researching the various javascript/jQuery libraries led me to Flot, and it was virtually love at first sight.

Graph of daytime highs and lows vs averages

Graph of daytime highs and lows in Meriden, CT. vs averages

Some helpful notes about Flot:

  • While Flot accepts JSON formatted data, make sure there are no quotes (") in the data. If you think about it, integers and floats are all you really need for the Cartesian coordinate system
  • All dates need to be *converted to milliseconds to be usable

* In PHP I used something like:
function convertDateToTimeMilliseconds($date) {
return strtotime($date) * 1000;

The beauty of Flot is you pass it the data (by assigning it to javascript vars), tell Flot what vars to use for the graph, assign labels, set aside a placeholder (for the graph to be written to), and that’s about it. You can customize colors, labels, tooltip text, etc. after the fact. It’s amazing and it just plain works!

Click here to see working example displaying graph of Weather Data for Meriden, CT, 2014 – 2015

Posted in Computer Stuff, jQuery | Tagged , , , , , | Leave a comment

John Wick – The Scottish Country Western Action Movie

I saw a trailer for John Wick the other night, and my curiosity was peaked sufficiently that I plan on watching it. I think, though, the editors/makers of the commercial/trailer for the movie, need a vacation, or need to be fired. Well, I hope it’s that, because otherwise it’s going to be a terrible movie.

Jumping forward to the important bits, they show you how he’s beaten up in what appears to be a home invasion. Seems to have something to do with somebody wanting his car. During the beating they decide to kill his dog. After that he’s out to set things straight.

Let me step back a bit.

The way Hollywood normally sets up this type of movie is fairly predictable. Good guy/girl (mostly guys), may be down on his luck, worn out, used and abused, taken for granted, is accosted/offended in some way, usually with the death or severe injury of a loved one. The hero is now, once again, reborn, a phoenix rising, righteous in all manners of brutality and ensuing explosions, graphic death scenes, and “witty” one-liners that set the hero apart from the bad guy(s). I’ve watched a lot of movies, and this IS the plot of many an action flick.

The problem I have with the commercial, though, is the sequence of highlights screwed up my head. The beating, the death of his dog? Okay, later we find out the dog is the last gift given to him by his deceased wife (whom, it is implied he dearly love(s/d)). Unfortunately, I’m already off in a far away land imagining a poorly toothed individual with little or no proper education, sort of a hill people kind of thing (sorry hill people), who’s saying, “You kilt muh dawg, and now I’m genna kilt you!” translation, “You killed my dog, and now I’m going to kill you!”

So you know, I’m laughing while writing this, days later, so you can imagine how I was when it first popped into my little pea brain.

Okay, so as if that’s not bad enough, the tangents are flying hard and fast. Saying ‘kilt’ has me imaging this with a Scottish twist. Yeah, I guess I’m gonna offend a whole lot of people today. Sorry about that. Anyway, the image of the hero and his dog wearing kilts, and the dog pulls it off exceptionally well, by the way, and I’m laughing even harder. The idea that this is the making of a perfect country western song rounds it off. Lyrics something like, ‘My wife is dead, you killed my dog, you stole my car, and now you wanna be friends, oh oh, you wanna be friends …’ start echoing off the empty walls inside my brain casing, and I’m laughing again.

The bottom line is, I hope this isn’t going to ruin the movie for me. Thanks a lot movie trailer editors!

Follow up:

Turns out the movie wasn’t half bad. =)

Posted in Movie Reviews | Tagged , | Leave a comment

Install A Linux Web Server On Your Windows 7 PC With Vagrant

First, I’d like to reference an excellent video tutorial that I used for my initial foray into the Vagrant world. Click here to see that tutorial.

Disclaimer: This blog entry does not necessarily follow safe computer/networking procedures. Use this only as a reference.

General outline:

  1. Install Oracle Virtualbox – you’re going to love this!
  2. Install Vagrant – gonna love this, too!
  3. Update and config Vagrant – PHP, MySQL, Apache.
  4. Connect and play!

Okay, I won’t go into any specifics but hopefully you can follow along. Download and install VirtualBox. This was the correct link on February 2, 2015. The installer you want is the Windows (32-bit/64-bit). You might have to answer some questions and do a reboot during the install (I don’t remember), but it should be fairly straight forward.

Install Vagrant as shown in the video referenced above. It really is an excellent tutorial.

Vagrantfile mods: “private_network”, ip: “” // uncomment this line so you can reach webserver at this address
config.vm.synced_folder “data”, “/var/www/html” // mod like this

Create data folder in ubuntu folder
add html files there and they will automatically show up on the server

Open a command prompt and change directory to vagrant install:

ex: cd C:\Users\robert\VirtualBox VMs\Vagrant\ubuntu

vagrant up

Download and install PuTTY – I used ‘A .ZIP file containing all the binaries (except PuTTYtel), and also the help files’

Using PuTTY ssh into box:
host name: vagrant@
port: 2222
open, then enter password of vagrant

Installing apache, mysql, and php:
sudo apt-get update // update packages
sudo apt-get install apache2
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
sudo /usr/bin/mysql_secure_installation // secures installation
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
sudo apt-get upgrade // upgrades packages

sudo apt-get install vim // I like vim for editor

cd /etc/apache2/
sudo vim apache2.conf

mod apache2.conf as below:

Options FollowSymLinks
AllowOverride None
Require all denied

<directory /usr/share>
AllowOverride None
Require all granted

<directory /var/www>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted

sudo a2enmod rewrite // enables rewrite
sudo service apache2 restart

Setup for HeidiSQL:
Go to C:\Program Files (x86)\PuTTY\puttygen.exe in Windows explorer
load: C:\Users\robert\.vagrant.d\insecure_private_key
Save private key: vagrantPrivateKey.ppk

Notes: winscp – doesn’t allow for commands that require input/feedback, so I went with PuTTY

// vagrant@, 2222, ssh – password once at command prompt

Tip: You can use virtual box to start vagrant’s install of linux and ssh from there.

Connect to MySQL:

HeidSQL Settings



You will need to tell HeidiSQL where plink.exe is located (click folder icon)

MySQL Workbench Settings

Initially, do not put in usernames and passwords – wait till you’re trying to connect and it asks for them (you can have them saved at that time).




Note: I had a lot of trouble getting Workbench to work at first. I would suggest trying HeidiSQL first.

Start and Stop

To make life easier I made 2 batch files to start and stop Vagrant. When opening a command prompt my computer naturally goes to C:\Users\robert\, so I placed the files there, and then created shortcut links on the desktop. You could also put a link to vagrantup.bat in your Startup (menu item):

@echo off
cd “C:\Users\robert\VirtualBox VMs\Vagrant\ubuntu”
vagrant up

@echo off
cd “C:\Users\robert\VirtualBox VMs\Vagrant\ubuntu”
vagrant halt


Additional fun things you can try. Once you have installing the system down, it takes less than 1/2 hour to completely redo, so experiment and have fun (I did):

sudo apt-get install ubuntu-desktop
startx or /etc/init.d/gdm start for gnome desktop and /etc/init.d/kdm start for the kde desktop or gnome
Ctl+Alt+T to bring up the Terminal.
sudo shutdown -h now or sudo halt
ctrl + alt + t => command prompt from desktop
ctrl + alt + F1 => command prompt from login screen
sudo adduser newuser

Posted in Computer Stuff, MySQL, PHP | Tagged , , , , , , | Leave a comment