Copied to clipboard

Flag this post as spam?

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


  • yang 21 posts 33 karma points
    Apr 27, 2010 @ 18:51
    yang
    0

    Query for a specific node

    Hi all,

    How is it possible to query umbraco for a node based on it's node name? I am not trying to query from xslt, I am trying to send the query from a custom aspx page with C#. Should I query with Lucene?

    Thanks in advance.

  • Tobias Neugebauer 52 posts 93 karma points
    Apr 27, 2010 @ 22:06
    Tobias Neugebauer
    1

    Hi,

    you can use umbraco.content.Instance.XmlContent (XmlContent is of type XmlDocument) and then use a normal XPath query like //node[@nodeName='QUERYNODENAME'] so this would be the complete statement:

    XmlNode node = umbraco.content.Instance.XmlContent.SelectSingleNode("//node[@nodeName='NAMETOQUERY']");

    Hope this helps

    Toby

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Apr 29, 2010 @ 00:09
    Hendy Racher
    0

    Hi Yang,

    Bear in mind that whilst nodes on the same branch will have unique names, there may be many nodes with the same name in different parts of the content tree.

    There seems to be quite a few requests to get nodes by name, so I thought I'd add a couple of methods to http://blog.hendyracher.co.uk/umbraco-helper-class/ to get a single node by name from a given parent node, and to get all nodes that match a particular name, incase unpublished nodes need to be queried.

    HTH,

    Hendy

Please Sign in or register to post replies

Write your reply to:

Draft