Copied to clipboard

Flag this post as spam?

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


  • Nigel Wilson 945 posts 2077 karma points
    Aug 26, 2011 @ 00:08
    Nigel Wilson
    0

    web.config vs GlobalSettings.ContentXML for referencing a node

    Hi there

    Seeking some feedback on which is the preferred way and also which is the most time efficient.

    I have a container within my site that I wish to "access" in a method. Obviously hard coding the node is not the solution, so I see 2 options:

    Option 1: Add an application setting in the web.config to store the node ID

    Pro: I would assume this is quicker

    Con: Remembering to maintain the data between production and development sites where the node ID's are different.

     

    Option 2: Use GlobalSettings.ContentXML and XPath to locate the node (there will only ever be one) and therefore access the NodeID.

    Pro: Self contained and will automatically locate the node

    Con: Possibly slower.

     

    I look forward to some feedback.

    Regards

    Nigel

  • Rich Green 2246 posts 4008 karma points
    Aug 26, 2011 @ 00:24
    Rich Green
    0

     Hi Nigel,

    I'm not 100% sure where you want to access the node from?

    I would certainly go with option number 2, as long as you retrieve the ID in the correct way (whichever was you chose) it'll be from the cached XML file, so performance shouldn't be an issue, especially as you'd only need to access it once.

    I would use 'GetNodesByXPath' in uQuery from uComponents here http://ucomponents.codeplex.com/wikipage?title=uQuery

    Rich 

     

  • Nigel Wilson 945 posts 2077 karma points
    Aug 26, 2011 @ 01:26
    Nigel Wilson
    0

    Hi Rich 

    Thanks for the prompt response.

    I have it working using the following code:

    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(System.Web.HttpContext.Current.Server.MapPath(umbraco.GlobalSettings.ContentXML));
    XmlNode xNode = xmlDoc.SelectSingleNode("//regionsAndStores");
    return new Node(Convert.ToInt32(xNode.Attributes["id"].Value));

    We do have the uComponents package installed on the site and I like the look of using the GetNodesByXPath method.

    The bit that I haven't been able to figure out is how to use the method to return just a single node.

    I tried the following but for now have commented it out... (we have a helper method to convert an object to a node, hence the ToNode() part)

    return uComponents.Core.uQuery.GetNodesByXPath("//regionsAndStores").ToNode();

    Thanks again for your help.

    Nigel

     

  • Rich Green 2246 posts 4008 karma points
    Aug 26, 2011 @ 01:34
    Rich Green
    1

    Hey Nigel,

    I think it returns a nodeset so something like this

     var nodes = uQuery.GetNodesByXPath("//regionsAndStores");

                    if (nodes.Count > 0)

                    {

                        var node = nodes[0];

       int regionid = node.Id;

    }

    Rich

  • Rich Green 2246 posts 4008 karma points
    Aug 26, 2011 @ 01:37
    Rich Green
    0

    As a side note, I don't know but I assume "xmlDoc.Load" would load another version of the umbraco.config file into memory which wouldn't be good for performance.

    uQuery will use the cached XML already in memory (the App_Data/umbraco.config file) so should be very quick.

    Regards

    Rich

Please Sign in or register to post replies

Write your reply to:

Draft