Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mark V 20 posts 150 karma points
    Jul 22, 2021 @ 14:55
    Mark V
    0

    XPath no longer supported?

    Hey,

    I often use xpath to retrieve specific content nodes. Except in 9 I can't seem to get it working.

    The functionality is there but it always returns null

    using (var cref = _contextFactory.EnsureUmbracoContext())
    {
       var something = cref.UmbracoContext.Content.GetSingleByXPath("root/homepage");
    }
    

    I also can't find the umbraco.config file anywhere either so I'm not sure if support has been dropped or it's just stored somewhere else now? It used to be stored in the App_Data folder which I think is no longer used by the default install of 9.

    This is using the release candidate of 9

    Cheers, Mark V

  • Søren Gregersen 417 posts 1719 karma points MVP 2x c-trib
    Jul 22, 2021 @ 16:07
    Søren Gregersen
    0

    Hi Mark,

    "umbraco.config" was replaced in Umbraco v8 by the "NuCache". v9 does not bring anything new, just a port to .Net 5 (.Net Core).

    Are you sure the xpath is correct? I would assume it should start with "/", like "/root/homepage"

  • Mark V 20 posts 150 karma points
    Jul 23, 2021 @ 08:36
    Mark V
    0

    Hey Søren,

    Yeah I'm thinking of 7 with the umbraco.config, whoops

    The query should be correct as I'm trying to migrate code from a site using umbraco 8 and the content is the same.

    Although It wasn't working yesterday I booted it up this morning and it's working now! 🤷‍♂️ Not sure what I did differently?

    Cheers, Mark V

  • Bjarne Fyrstenborg 1214 posts 3590 karma points MVP 5x c-trib
    Jul 25, 2021 @ 10:31
    Bjarne Fyrstenborg
    100

    Hi Mark

    Mostly you don't need to use XPath in v8 and v9 and because of the new caching layer the LINQ querying is faster. XPath is still supported because it is used a few places like in MNTP property editor, but there is no real XML document, so it is a representation to use XPath queries.

    So in your case I would use the following:

    using (var cref = _contextFactory.EnsureUmbracoContext())
    {
        var cache = cref.UmbracoContext.Content;
        var homePage = cache.GetAtRoot().FirstOrDefault() as HomePage;
    }
    
  • Mark V 20 posts 150 karma points
    Jul 27, 2021 @ 09:33
    Mark V
    0

    Hey Bjarne,

    Thank you, I'll avoid using xpath for the future 👍

    Cheers, Mark V

Please Sign in or register to post replies

Write your reply to:

Draft