1
votes

I have the following Sitecore queries:

  1. /sitecore/content/Home/Clubs//17th
  2. /sitecore/content/Home/Clubs//20th

Of specific note is I'm using the descendant axes feature of the Sitecore Query language (//), with /sitecore/content/Home/Clubs being my context.

I have my content structured as such:

  1. /sitecore/content/Home/Clubs/Chicago/17th
  2. /sitecore/content/Home/Clubs/New-York/Downtown/20th

When I run queries 1 and 2 in XPath Builder, I get content items 1 and 2; respectively. This is what I expect. However, when I run those same queries through Sitecore's API, I get a content not found error.

The following queries will work with Sitecore's API, mind you:

 * /sitecore/content/home/clubs/*/17th
 * /sitecore/content/home/clubs/*/*/20th

What I'm trying to accomplish is one query where I can get both children AND grandchildren of a content item with a specific name; a query like this:

/sitecore/content/Home/Clubs//{contentItemName}

I know I could just try

/sitecore/content/Home/Clubs/*/{contentItemName}

and fallback to

/sitecore/content/Home/Clubs/*/*/{contentItemName}

if that doesn't work, but that seems like a hack.

Is there anyway I can get the query I verified in the XPath builder works to work with the Sitecore API?

1
Try /sitecore/content/home/clubs//17th//* - That should get you all children and grandchildren of 17th item (which in turn is a child or grandchild of clubs). If that doesn't work then post up your C# code too.jammykam
don't forget to use fast query instead of queryVikram

1 Answers

1
votes

I think you need the following in XPath builder:

/sitecore/content/Home/Clubs//*[@@name='20th']

or in the API:

/sitecore/content/Home/Clubs//*[@@name='{contentItemName}']