Copied to clipboard

Flag this post as spam?

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


  • Luke 110 posts 256 karma points
    Aug 14, 2015 @ 07:35
    Luke
    0

    Drop Down List Data Type and Content By XPath

    Hi All,

    I have a property on my document that is a Dropdown List I am trying to work out how to get content by XPath with either the value or id of an item.

    For Example

    var docs = Umbraco.TypedContentAtXPath("//NewsItem[@newsType = 83");
    

    Or

    ar docs = Umbraco.TypedContentAtXPath("//NewsItem[@newsType = General");
    

    Best Regards, L

  • Lars-Erik Aabech 350 posts 1102 karma points MVP 8x c-trib
    Aug 14, 2015 @ 10:36
    Lars-Erik Aabech
    1

    I'm pretty sure your newsType value isn't an attribute (prefixed with @), but an element. In which case it would be

    //NewsItem[newsType=83] 
    

    or

    //NewsItem[newsType='General']
    

    (Notice the single quotes when comparing strings)

    I recommend installing the XPath navigator extension to Visual Studio if you're using VS. You can search by xpath in /App_Data/umbraco.config. It makes it a breeze finding the correct xpath expression.

  • Luke 110 posts 256 karma points
    Aug 14, 2015 @ 13:16
    Luke
    1

    Hi Lars,

    I had put the @ in the post but it was not part of my code. It was because of the single quotes - thank you kindly.

    And thank you for the VS plugin link.

    And just so people know - it is the text string that you use not the id.

    Regards, L

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies