tags:

views:

71

answers:

2

I am having an issue with an XPath query I'm performing for a Sitecore CMS system.

This query works fine:

/root/content/Meta-Data/Tips/*

But when I try this:

/root/content/Meta-Data/Tips/*[@SomeAttribute='somekey']

I get an error which says "End of string expected at position 22" which is where the dash character is found. I was under the impression that the dash was not a special character in XML... am I doing something wrong here? Do I need to encode this in some way? Or is this a bug in the XPath parser? Any suggested workarounds?

+5  A: 

Change this:

/root/content/Meta-Data/Tips/*[@SomeAttribute='somekey']

To this:

/root/content/#Meta-Data#/Tips/*[@SomeAttribute='somekey']
dhulk
That works. Interestingly, it fails if I exclude the [@someattribute] filter. You have a source for this? I don't see it mentioned in the W3C Xpath doc. It aslo fails on the XPath tester awshepard links below.
Bryan
http://sitecoredev.blogspot.com/2006/04/sitecore-xpath.html
dhulk
I see... it's not *really* a true XPath implementation. Thanks for the link.
Bryan
A: 

According to the XML spec for characters in tag names, the hyphen should be a valid character. I've done a bit of XPath testing with this site and found it helpful for comparing results with other parsers.

awshepard
Thanks. Both original queries work OK here with the dash node name.
Bryan