Search code examples
xpathumbraco

Get all nodes except some (for Umbraco) using XPath


I tried to get all nodes except one provided by me, using XPath... The code:

UmbracoHelper.TypedContentAtXPath("//[not(contains(@alias, 'myNode1') or contains(@alias, 'myNode2'))]");

But I receive an error:

Expression must evaluate to a node-set.

Where is my mistake ?


Solution

  • You missed to specify element name to which the predicate (the expression within the square brackets) will be applied. It might be a specific name -which I don't know exactly- or a wildcard (*, which means elements of any name) :

    //*[not(contains(@alias, 'myNode1') or contains(@alias, 'myNode2'))]