Click here to Skip to main content
15,885,027 members
Articles / Programming Languages / Javascript
Article

JavaScript XPath Analyzer

Rate me:
Please Sign up or sign in to vote.
4.94/5 (17 votes)
10 Aug 20032 min read 63.5K   1.1K   22   6
A simple HTA desktop application that allows you to query XML documents using XPath.

Introduction

I've been working on XML and Xpath for several years now. However, I tend to get a little rusty with the Xpath syntax every now and then or just need a simple tool to test a complex query. After looking for a while, I didn't see much out there that was worth while, so I decided to write one of my own about a year ago. Hopefully everyone here will find it as useful as I have.

The XPath Analyzer is a simple utility tool that will allow you to evaluate queries against an XML instance. It's written as an HTA application. For those who aren't familiar with HTAs, it's basically an HTML file with different security permissions and a few extensions. Right now you're probably saying to yourself, "Special Security Permissions! Screw that!", let me reassure you that I'm not doing anything malicious or making any attempt to violate your privacy. But if you don't believe me, the code is not encrypted, so take a look for yourself before running the application.

How to use

To launch the application, unzip the files and double click on XPathAnalyzer.hta. Next, load a well formed XML document from your file system by clicking the "Load" button. By default, Xpath Analyzer is set to use MSXML 4.0. If you don't have MSXML 4.0, XPath Analyzer will prompt you to install it. However, if you choose not to install, you can select MSXML 3.0 which is installed by IE 6.0. This will load the XML instance into memory and display the XML in the top pane. Xpath Analyzer will also detect all your namespace bindings from the instance and load them to the namespace bindings drop down.

You can also edit the XML document that's loaded in the top pane. It's an extremely crude XML editor. In fact, it's just a div tag that has the contentEditable attribute turned on. Once you're satisfied with your changes, you must click "Reload" to accept those changes.

Now that your document is loaded, you can begin writing your Xpath queries in the text box. Click "Evaluate" to test your query. The results are then displayed in the lower panel.

Points of Interest

  1. Included in this application is a tabstrip behavior that you can reuse.
  2. I wanted the XML documents to be color coded in the two panels, so I had to dynamically transform the XML to HTML. In doing research for this feature, I ran into an article posted on Developmentor's website that pointed to the default XSL file that IE uses to display XML. Unfortunately it was written for MSXML2, so I translated the file to XSLT.
  3. The application also has a link to MSDN's XPath documentation, in the right tab of the tabstrip.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralPlease use Msxml6 instead of Msxml4 Pin
Umut Alev17-Dec-06 21:37
Umut Alev17-Dec-06 21:37 
Generalasync Pin
Tom McDonald13-Apr-06 0:15
Tom McDonald13-Apr-06 0:15 
AnswerRe: async Pin
Umut Alev20-Dec-06 20:12
Umut Alev20-Dec-06 20:12 
GeneralNice! Pin
jpsiv24-Feb-06 17:30
jpsiv24-Feb-06 17:30 
GeneralVery usefull Pin
Jim Taylor12-Aug-03 22:12
Jim Taylor12-Aug-03 22:12 
GeneralRe: Very usefull Pin
khoi pham13-Aug-03 3:36
khoi pham13-Aug-03 3:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.