Matt Youngblut’s Blog

May 14, 2008

XPath - Common Mistake

Filed under: day-to-day — Matt @ 2:45 pm

When dealing with XPath, an extra forward slash (/) can make the difference between your application performing and making the decision that XPath just isn’t the solution for you.  So what is the difference between /Product and //Product?  Huge.

/Product means “go find the Product element that are my children”.  The engine only needs to look at child nodes relative to the current location.

//Product means “go find all of the Product elements that are a descendant of mine - I don’t care where they are at”.   This means that if your document is 50 levels deep, the engine will look through each and every one of them to find a product element.  If you have 10,000 elements to look through and then you have to go diving down the tree as well, it is obviously a more expensive than it needs to be.

Sometimes you don’t know where the element will reside in your XML document, so // makes sense.  However, if you know where you are looking, you should always use /.  Neither is “wrong”, but one can be a LOT more expensive than the other.

I’ve seen two XPath queries written today - one at work and one on the web, and both of them were using the inefficient double slash (//).  I hope this helps anybody who is doing any querying using XPath.

May 6, 2008

Greatest Living Beard

Filed under: day-to-day — Matt @ 1:02 pm

AKA Beardface

June 25, 2007

One man’s attempt to control the pet population

Filed under: day-to-day — Matt @ 11:09 am

No, my dogs are already fixed. I’m just trying to control where they go. Like if put them in the pen in the garage (which allows them to go outside via the doggie-door, I don’t expect them to be running around the garage like they were today when I got home.

So I’m on attempt #6 to contain them:

  1. Put up a pen
  2. Tethered pen to wall because they got smart enough to move the pen
  3. Patched corners of door, as Harley discovered how to “chew through” chain-link fence
  4. Bound plywood to door because the patching didn’t work
  5. Used a heavy piece of oak, plus rolls of carpet, bags of sand, and bags of water softener salt because Harley ripped the plywood to shreds
  6. The latest attempt (today): Put up a wrought-iron fence on the outside of the door, tethered by 1/8″ steel cables, because Harley figured out how to move the piece of oak and drag everything into the pen and chew it to shreds.

It now looks like a window in Miami or New York City at the bottom of the door. If this doesn’t work, I’m going to use electric fencing. I’ve been thinking about doing that since attempt #4, but it just seems so inhumane to me.

Blog at WordPress.com.