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?
There is no way to escape characters at the XPath level, so you can't have a literal XPath string containing both kinds of quote.
The dot, or period, character (“.”) in XPath is called the “context item expression” because it refers to the context item. This could be a node (such as an element, attribute, or text node), or an atomic value (such as a string, number, or boolean). When it's a node, it's also called the context node.
The null character. Seriously. Because an XPath is supposed to support any XML document, it must be capable of matching text nodes that contain any allowed Unicode character. However, XML disallows one character: the null character.
/* selects the root element, regardless of name. ./* or * selects all child elements of the context node, regardless of name.
Change this:
/root/content/Meta-Data/Tips/*[@SomeAttribute='somekey']
To this:
/root/content/#Meta-Data#/Tips/*[@SomeAttribute='somekey']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With