all things Sitecore related

Escape characters / words in a Sitecore query

By on February 2, 2012 in Sitecore with 2 Comments

There are a few characters and words you need to escape while using Sitecore query. You can escape special characters wrapping them in a #. For example a hyphen in a query needs to be escaped.


string query = "/sitecore/content//*[@#site-title#=’Example Value’]";

In the previous example we use the single quote (‘) to wrap the field value. Using a single quote in the field value will break the parser.  At this point you can use an escaped double quote to wrap the field value containing the single quote.


string query = "/sitecore/content//*[@#site-title#=<strong>"</strong>It’s great<strong>"</strong>]";

There is also a list of words that  needs to escaped when used in the path (before //*), there words are :

  • ancestor
  • and
  • child
  • descendant
  • div
  • false
  • following
  • mod
  • or
  • parent
  • preceding
  • self
  • true
  • xor


string query = "/sitecore/content/#this or that#/*[@#site-title#="Example Value"];

More information about the Sitecore Query Syntax on SDN:

Tags: ,

About the Author

About the Author: Pieter is Technical Marketing Manager for Sitecore Netherlands and owner of He has more than ten years experience with software developing in multiple programming languages and with different Content Management Systems. Before joining Sitecore Pieter was a lead developer for multiple Sitecore and .Net projects, he joined Sitecore in 2011 as an Solution Architect in The Netherlands, after two years as an Solution Architect he joined the Technical Marketing department. In the role as Techinical Marketing Manager he is responsible for the Global MVP program and the Sitecore technical branding strategy. You can follow Pieter on twitter: @pieterbrink123 or Google+ .


If you enjoyed this article, subscribe now to receive more just like it.

There Are 2 Brilliant Comments

Trackback URL | Comments RSS Feed

  1. Brian says:

    It might just be me but the following example is really confusing:
    string query = “/sitecore/content//*[@#site-title#=It’s great]”;

    Are those strong tags actual formatting or part of the expression?

    Also, do you know how to escape a single quote when it’s part of the value being updated as part of a “update set” expression? I cannot figure it out.

    • Brian says:

      Ha ha.. I can see the strong tags are working as they should in the comment I posted so I understand that now.
      Still interested in your reply to my second question.

Post a Comment

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