Geeks With Blogs
Colin Maunder

I've just spent that last week building a translator, allowing us to convert a new customers catalogue data into a form our sales system can cope with. Luckily the source data was XML, so it was already in a form I could use, but there was no schema, and the structure was a bit flaky in places.

I started off trying to read through the data, but the structure was just to messy, in the end I figured out I could probably do most of the grunt work with XPath. This approach seemed promising, and I got good results initially, however my lack of XPath experience quickly started to let me down. Changing your XPath expression in code (C#) is possible, but typically means a re-compile - especially when you have anonymous methods, which I use a lot for sorting collections.

So I went in search of a good XPath tutorial, and I was somewhat disappointed with what I found. There are a few - but they are a bit lacking, the W3Schools XPath Article one was the most complete, and an XPath article on Google Knol had some nice examples. If anyone comes across a really good XPath tutorial let me know!

What I did find while I was looking was a free XPath Viewer, it highlights the selected nodes as you type your XPath query. This made the learning process so much quicker, and allowed me to debug a lot of my XPath queries before they got as far as the code. The Liquid XML Studio XPath viewer also added itself to Visual Studio 2008 which made my life even easier.

Liquid XML Studio XPath Viewer

Posted on Friday, December 19, 2008 7:13 AM | Back to top

Comments on this post: Building XPath Queries

# re: Building XPath Queries
Requesting Gravatar...
Did you look at Visual XPath? It is not perfect but get the job done and also generates some C# code which you can directly paste into visual studio. thanks,Nauman
Left by Nauman on Dec 23, 2008 3:21 PM

# re: Building XPath Queries
Requesting Gravatar...
My favorite is the XPath Checker Firefox extension-- it does the same thing as the tool you mentioned, shows you what your current xpath is selecting, but is really handy on the web.
Left by CarolN on Dec 24, 2008 12:22 AM

# re: Building XPath Queries
Requesting Gravatar...
The zvon tutorials are really the best I've seen on the net:

It's important to know that when you are learning xpath you are very much learning xml at the same time. Good luck!

Left by Ivan on Dec 24, 2008 2:26 AM

# re: Building XPath Queries
Requesting Gravatar...
Take a look at SketchPath
Left by Will Irwin on Dec 30, 2008 2:07 AM

Your comment:
 (will show your gravatar)

Copyright © CMaunder | Powered by: