Skip to main content

Posts tagged with 'ASP Classic'

Of all the blog post titles I'd like to write, "Parsing XML in ASP classic" is definitely not at the top of my list. But sometimes you just have to suck it up. So here we go...

Given a string that contains XML (maybe the result of an Ajax request or the contents of some config file), let's get some values out of it.

Here's some sample XML that I'll be using:

Create a MSXML2.DOMDocument.6.0 object. Use its LoadXML method. You can then use the selectSingleNode and XPath to get values out. For instance, if I wanted the value for ShoeSize in the above XML, I could use an XPath of //@ShoeSize to get a node. Then use the text property of that node to get the value.

There ya go. If you aren't an XPath whiz, you can use this XPath tester to help you through it.

Here's a little weirdness that I discovered this week. (I think this may just apply to ASP Classic but I'm not 100% sure).

I was writing some ASP Classic that reads some information from HTTP headers (which are put into the request from a mobile application). For some reason, the data wasn't showing up:

Turns out that the server replaces underscores with dashes. At first, this was just a wild guess on my part, but luckily it worked out.

A bit annoying, but I guess I learned something new!

Hi! This is one of the most popular posts on my blog, just wanted to say "thank you!" for stopping by! Also, sorry about the whole ASP Classic thing. But good luck! If you're into podcasts, check out The Cross Cutting Concerns Podcast, with interviews about interesting and fun technology.

I've recently had to write some ASP Classic. Don't worry, it's not like I'm writing new features, just integrating with old ones. So, since this is an ancient technology, some of this may be old news to you. But much of it was new to me, and I'm a developer with some years of ASP Classic experience.

Most of the stuff I had to do was pretty minor, but one major thing I found interesting was that I had a need to make an HTTP request in ASP classic. This turns out to be not so bad.

The trickiest part was figuring out that I had to explicitly specify the content type, since it apparently doesn't set a default.

So, yay! But also, uh oh. Now I have a response, but it's in Json. How the heck do I deal with that in ASP Classic? I was already worried about having to create an XML endpoint or finding some hacky JSON parser written in VBScript. But I took a deep breath and Googled it first. I was pleasantly shocked with what Stack Overflow told me about parsing Json in ASP. Did you know that ASP Classic is typically associated with VBScript, but actually can support other languages, like JScript and PerlScript? JScript is Microsoft's implementation of ECMAScript (commonly referred to as JavaScript), which they made available server-side via ASP long before you had a crush on Node.js. (Yeah I'm trolling a bit, but give me a break: as I write this, I've been layed up with the flu watching a House, M.D. marathon on Netflix, so I'm feeling a bit snarky).

ANYWAY

If we can run JScript and VBScript with the same ASP Classic page, then guess what, we can use Douglas Crockford's JSON library. It's so perfect and simple, and I wish I came up with it on my own.

That's about 100 times more elegant of a solution than I even expected when I started on this code.

Matthew D. Groves

About the Author

Matthew D. Groves lives in Central Ohio. He works remotely, loves to code, and is a Microsoft MVP.

Latest Comments

Twitter