Click here to Skip to main content
Click here to Skip to main content

JavaScript XPath Analyzer

, 10 Aug 2003
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

khoi pham
Web Developer
United States United States
No Biography provided

Comments and Discussions

 
GeneralPlease use Msxml6 instead of Msxml4 PinmemberUmut Alev17-Dec-06 22:37 
Generalasync PinmemberTom McDonald13-Apr-06 1:15 
AnswerRe: async PinmemberUmut Alev20-Dec-06 21:12 
GeneralNice! Pinmemberjpsiv24-Feb-06 18:30 
GeneralVery usefull PinmemberJim Taylor12-Aug-03 23:12 
GeneralRe: Very usefull Pinmemberkhoi pham13-Aug-03 4:36 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 11 Aug 2003
Article Copyright 2003 by khoi pham
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid