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?
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:
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::*");
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.
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?
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
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).
HTH,
Hendy
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
is working on a reply...