Copied to clipboard

Flag this post as spam?

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


  • andrew shearer 510 posts 659 karma points
    Feb 07, 2011 @ 05:31
    andrew shearer
    0

    document vs nodefactory in 4.6.1

    having a complete mind blank today..

    im adding some content nodes to umbraco programatically as part of a data import and i want to find an item in the content tree that has an attribute with a particular value. it would be anywhere in the tree hierarchy. Due to the nature of what im doing XLST and 'currentnode' concepts arent applicable.

    which API method should i use? document or nodefactory? linq?

     

  • Sascha Wolter 615 posts 1101 karma points
    Feb 07, 2011 @ 06:26
    Sascha Wolter
    0

    Hey andrew,

    don't use Document if you just want to look a property or something up on a Umbraco node, the Document object is the 'real' deal and gets back much too much info that you don't need. Linq is definitely a nice idea, the nodefactory will work as well, check out this method:

    Node.GetNodeByXpath(string xpath)

    Haven't used it myself yet, but sounds promising!

    Hope that helps,

    Sascha

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Feb 07, 2011 @ 08:52
    Hendy Racher
    0

    Hi Andrew,

    You'll want to use the nodeFactory for reading content (internally this works with the published XML), and the Document API to create / update content.

    The uQuery helper library in uComponents might be useful; there's a method to return a List from an XPath expression, and it'll work with $currentPage, and there are other extension methods on the Node object to be able to set properties (internally this uses the Document API).

    using uComponents.Core;

    List nodes = uQuery.GetNodesByXPath("$currentPage/child::*");

    HTH,

    Hendy

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Feb 07, 2011 @ 10:15
    Richard Soeteman
    0

    Hi,

    When you need readonly access don't use the API as Sascha and Hendy already mentioned. When you want to add data use the Document API. Since you mentioned you need it for an import. You might want to checkout the CMSImport Package as well.

    Cheers,

    Richard 

Please Sign in or register to post replies

Write your reply to:

Draft