Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath and special characters

Tags:

xpath

sitecore

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?

like image 728
Bryan Avatar asked Apr 23 '10 20:04

Bryan


People also ask

How do you escape special characters in XPath?

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.

What does character represent in XPath?

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.

Which symbol is not used in XPath?

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.

What does /* mean in XPath?

/* selects the root element, regardless of name. ./* or * selects all child elements of the context node, regardless of name.


1 Answers

Change this:

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

To this:

/root/content/#Meta-Data#/Tips/*[@SomeAttribute='somekey']
like image 151
Blair Scott Avatar answered Sep 29 '22 11:09

Blair Scott