XPath Pain and Halo Hell

Yesterday I was struggling to get my XPath queries to work. This was the first time I've ever used a schema to validate the document, and this ended up forcing me to deal with namespaces in the queries. This is actually a good thing, as I need to enforce the validity of the data in the XML file (as it's going to be generated by another company and I want to make sure they're doing it right). But I could never get the queries to work. Of course, the problem was a simple fix (isn't is always). Here's the scenario (not the same XML structure but the idea is the same). I first need to get elements from the root element, like this:

/Books/Book

I create my XPathExpression object from this statement, and everything works OK. Now, as I'm iterating through each Book element, I want to get each of its Chapter elements. So I thought this query would work:

/Chapter

Of course, this didn't work. My query should've been:

./Chapter

as I need to be relative to the current node. D'oh!

Then, when I got home, I realized that I forgot to save my Halo progress from the night before. Damnit! At least I knew what to do this time, so I worked my way back to where I was before, and went to bed. How I wish the XBox came with some kind of Alt+F+S sequence that would work with every game.

* Posted at 02.04.2003 09:34:00 AM CST | Link *

Blog History