Skip to main content

Technical

Sitecore Query Error: End of String Expected at Position

A group of diverse coworkers working on the computer together

A couple of weeks ago a coworker experienced a serious issue while working with Sitecore Query. He spent a lot of time trying to run a query for an easy search but it was not working. My friend was pretty sure the syntax was well formed but when the query was executed the result was an error :

End of string expected at position ##

He tried the Sitecore Query in the XPath Builder tool from the Sitecore’s Developer Center and verified the same error was displayed there. I was walking by his cubicle and we took a look at the query at XPath Builder, we noticed that the position mentioned by the error was an separator character in the field’s name, it was composed by two words. We were facing a case of Sitecore Query is waiting for the End Of String that never arrives. It was for sure for us the field name must be enclosed by some symbol… we use our developer logic and sixth sense to remember all symbols used for this purposes but none of them worked at all.He continued researching and found a post that explained the ‘#’ symbol is used to enclose special item’s names every time a special character were included. He added the ‘#’ and the sitecore query worked like a charm.

A name created from more than one word is just one example of item names that must be enclosed by the ‘#’ symbol. Besides the dash character, that replaces the empty space between words in a name, there are other scenarios that require attention as described in the following table based on Sitecore documentation.

Must be enclosed when Item name…

example

contains dashes in name (“-”)

/sitecore/content/#Contact-Us#]

contains “and” or “or” word and is used before ‘//*’ symbols

/sitecore/content/Home/#News and Events#]//*

Starts with digits

/sitecore/content/Home/News/#2013#/January

Inspired in this dark issue, I tried some Sitecore Queries using XPath Builder with the results displayed in the following table.

/sitecore/content/home//*[@Latest

News Header=’Latest News’]

WORKED: Found 5 results

/sitecore/content/home//*[@#Latest News Header#=’Latest News’]

WORKED: Found 5 results

/sitecore/content/home//*[@News and events=’Find the event’]

FAILED: Type Mismatch

/sitecore/content/home//*[@#News and events#=’Find the event’]

WORKED: Found 1 results

/sitecore/content/home//*[@Join-Us=’Contact email’]

FAILED: Type Mismatch

/sitecore/content/home//*[@#Join-Us#=’Contact email’]

WORKED: Found 1 results

/sitecore/content/home//*[@1st=’First Story’]

FAILED: Identifier expected at position 28.

/sitecore/content/home//*[@#1st#=’First Story’]

WORKED: Found 1 results

It’s important to remark that although the ‘#’ symbol fixed the issue, there is another post that mentions the “End of string expected” is a symptom of a bug that appears when you’re using Fast Query and SelectSingleItem with Sitecore 6.2. The same post mentions it will be fixed in 6.3… Meanwhile the workaround is to use Sitecore Query instead of Fast Query.

You can get more details from the following Sitecore reference documentation here.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Categories
Follow Us
TwitterLinkedinFacebookYoutubeInstagram