84

I know there are some online regex evaluators.. very useful, matching in real time. They are like web applications of RegexBuddy.

I was wondering if there is a similar thing for xPath selectors? I am just learning them and it would be valuable to me.

Is there an online tester that allows you to input XML and then an xPath selector and match (live would be better, but I doubt someone has written a JavaScript interpreter?) them?

Thanks

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
alex
  • 479,566
  • 201
  • 878
  • 984

11 Answers11

87

I notice that the only "online" checker in the answers seems a bit clunky. It requires submission to a server, and it doesn't handle namespaces properly.

I thought I could do better, and that such a tool would be quite useful, so I made one. I realize it is slightly self-promoting to mention it here, but it does specifically answer the question, I think!

http://chris.photobooks.com/xml/default.htm

Mine can apply an xpath expression to an arbitrary XML document and display the results. It can also beautify, or pretty-print an XML document, and apply an XSLT transformation to it. All processing is done by the browser, and it should work in IE6+, Firefox, Opera, Chrome, and Safari.

Please let me know if you encounter any issues with it!

Chris Nielsen
  • 14,731
  • 7
  • 48
  • 54
  • Why do I have to press refresh? It should use some AJAX magic! That, and displaying/highlighting only the matches. (Just like Rubular does for regex.) – ashes999 Jan 06 '11 at 17:08
  • 2
    Sorry, the "refresh" button does not actually refresh your browser, it merely re-executes the JavaScript rendering process. I guess I should rename it, huh? There is no AJAX because no XML is ever sent to the server at any time--it's processed 100% in JavaScript. I will add highlighting when I have time; keep in mind this is a personal project for me. Nobody pays me for this! ;) – Chris Nielsen Jan 07 '11 at 04:07
  • 1
    awesome little tool saves me having to download the xpath visualiser which seems to crash alot – Exitos Jun 22 '11 at 10:07
  • 1
    Awesome tool. Is the source available ? – Tom Chiverton Sep 28 '11 at 08:55
  • 4
    Sure is! Right click on the page and select "View Source!" ;) There's no explicit license. I'd appreciate it if you'd consider it to be under the same creative commons license as any other StackOverflow post. The source is not exactly production quality, so caveat emptor. – Chris Nielsen Oct 17 '11 at 12:57
37

This is not an online tool; instead it's a Windows app, more along the lines of RegexBuddy, but for XPath.

XPathVisualizer.

screen shot http://i29.tinypic.com/1zwp5ix.jpg

Cheeso
  • 189,189
  • 101
  • 473
  • 713
  • Wish I'd know about that a couple of years ago. – scope_creep Oct 05 '09 at 00:15
  • General observations: A good first exercise in producing a WinForms application. Not too-advanced, with too restrictive platform requirements, and a little bit too late. The real XPathVisualizer has been around since the year 2000 with thousands of downloads each month. XPath is clearly not a good area in which to try to rediscover the wheel. – Dimitre Novatchev Apr 24 '10 at 19:24
  • 1
    @Dimitre Novatchev, I can understand being proud of your own project, but at least resolve that your site is flagged as malware! – Aardvark Nov 12 '10 at 17:21
  • @Aadvark: This is not "my site". Please, propose to host the XPath Visualizer and I might consider it. :) – Dimitre Novatchev Nov 12 '10 at 17:30
  • @Dimitre Novatchev, I would if I could! – Aardvark Nov 12 '10 at 18:08
  • Not bad. I just wish it used some "AJAX magic" by auto-evaluating instead of making me hit Eval every few seconds :/ – ashes999 Jan 06 '11 at 17:10
  • @ashes99 - it now has "AJAX magic". Actually there's no Javascript at all, but it automatically evaluates the XPath as you type it. You need v1.3 to get that feature. – Cheeso Jun 04 '11 at 21:20
28

Edit: The XPath Visualizer for IE now has a new, safer home, thanks to the kindness of Lars Huttar. Also there is the XPath Visualizer for FF.

The XPath Visualizer has been available for more than 10 years and has helped thousands of people learn XPath the fun way. Available for IE and for FireFox.

The XPath Visualizer is a popular tool for learning XPath by playing with XPath expressions. Free and open source.

Allows any XPath expression to be evaluated against a given XML document and displays the results hi-lighted in the xml document (if they are node(s)) or in a separate box (if the results are atomic values).

Allows xsl:variable-s to be defined and then used in XPath expressions.

Allows xsl:key-s to be defined and then referenced by key() functions within XPath expressions.

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
  • 31
    warning, according to google the linked site contains malware: http://safebrowsing.clients.google.com/safebrowsing/diagnostic?client=Firefox&hl=en-US&site=http://www.topxml.com/code/cod-422_9827_xpath-visualizer-for-the-mozilla-browser.aspx – Peter Recore Dec 23 '09 at 19:45
  • I will be considering moving the download to a safe site. Any suggestions? – Dimitre Novatchev Apr 13 '10 at 13:09
  • @Dimitre, Firefox version can be accessed from somewhere? – Flack Jan 07 '11 at 03:17
  • @Flack: It was on topxml.com (don't access it -- contains malware). I also have it, but since recently it stopped working on FF and I don't have an idea why and also no time to investigate. Do you want the code and to try make it working once again? They might have changed the way XSLT transformations are performed. The existing code was written around 2002-2003 and was working until recently. – Dimitre Novatchev Jan 07 '11 at 03:28
  • @Dimitre, no obligations :), but I certainly would like to see the sources. Also, I consider you could publish it on github or sourceforge like XSelerator. I guess, stating that it needs to be updated is enough to get no unnecessary critics. – Flack Jan 07 '11 at 03:33
  • @Flack: Since some time the XPV is available at a safe site, thanks to Lars Hutar -- see the EDIT at the top of my answer. The download has always contained the source code. :) – Dimitre Novatchev Feb 02 '11 at 19:32
  • @Dimitre, I guess you should remove "(warning: link not safe)" and link to Firefox version on topxml. – Flack Feb 02 '11 at 20:28
  • @Dimitre, and, is source code at huttar.net also actual for Firefox or it had major differences (while it was available and worked)? – Flack Feb 02 '11 at 20:34
  • @Flack: No, at huttar.net there is only the XPV for IE. Anyway, it seems that in the most current versions of FF, XPV is not working. Are you interested in getting the code and making it work again? – Dimitre Novatchev Feb 02 '11 at 20:35
  • 2
    @Dimitre. In fact I am. It really messes with me to start IE just for XPV :) – Flack Feb 03 '11 at 07:51
  • @Flack: Then why don't you contact me (dnovatchev) on the mail provided by Google? – Dimitre Novatchev Feb 03 '11 at 13:32
  • @Dimitre. Do you plan to include Firefox version with a safer link? It's still a firework of antivirus alerts :( – Flack Feb 23 '11 at 19:45
  • @Flack: I need to ask @LarsH first, it is his site. @LarsH, will you kindly allow me to put the FF version of the XPath Visualizer also there? – Dimitre Novatchev Feb 23 '11 at 22:32
  • @Flack: The XPV for FF has been uploaded to Lars Huttar's site and the link in this answer has been updated accordingly. – Dimitre Novatchev Feb 27 '11 at 17:41
  • 2
    @Flack: Yes, and thank *you* for helping to make this possible. – Dimitre Novatchev Feb 27 '11 at 22:05
  • +1 For this collaborative behaviour. –  Mar 19 '11 at 02:19
  • The FireFox version doesn't work. Pressing 'process file' says [Exception... "Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)" location: "file:///C:/DOCUME~1/TCHIVE~1/LOCALS~1/Temp/XPathVisualizer/XPathMain.htm Line: 43"] – Tom Chiverton Sep 28 '11 at 08:48
  • @TomChiverton: This, of course, means that you have unzipped the distribution archive in the wrong place -- try unzipping it into a directory, from which FF can open local .htm files. – Dimitre Novatchev Sep 28 '11 at 12:13
17

Yep! Try the XPath Checker extension for Firefox. It's a handy tool.

John Feminella
  • 303,634
  • 46
  • 339
  • 357
5

Here is a nice one: http://www.xpathtester.com/

user431529
  • 2,222
  • 1
  • 17
  • 16
  • Although I've only tried simple xpath expressions, so far xpathtester has worked well for me too. – coder_tim Jan 06 '11 at 23:07
  • I've been working with it for a while and I really like it. It has a Clean interface and instead of marking the results over the XML, it generates the resulting node/list/text. – CaBieberach Jun 17 '11 at 14:16
2

i use this one

http://xpath.online-toolz.com/tools/xpath-editor.php

inisty
  • 21
  • 1
2

You can also use Notepad++ with it's XMLTools plugin - it has xPath evaluator

Dror
  • 7,255
  • 3
  • 38
  • 44
1

I found the following tool the most helpful.

Allans Online XPath Tester

The other tools mentioned below either required a particular browser or had some issue with loading xml or using some of the more obscure XPath expressions I was using. This tool did not.

1

Remove It Permanently, a firefox extension available on AMO, has such visualization functions. It would be nice if it had firebug type power for the slightly advanced adblocker.

screenshot http://i49.tinypic.com/n65a3d.jpg

sth
  • 222,467
  • 53
  • 283
  • 367
1

If you're on Firefox, you can use Firebug + Firefinder, which enable you to filter elements based on XPath expressions, and even post the matched code to jsbin in a snap.

asymmetric
  • 3,800
  • 3
  • 34
  • 52
1

Here is one...

XPath Query Expression Tool

alex
  • 479,566
  • 201
  • 878
  • 984