Copied to clipboard

Flag this post as spam?

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


  • Stephanie 39 posts 101 karma points
    Jan 03, 2012 @ 17:35
    Stephanie
    0

    Need some help traversing nodes in C#

    Here's the situation:

     

    I have  List of nodes retreived using uquery.

    For each of those nodes, I need to access the node ID's contained in a multi content picker.

    For each of those node ID's, I need to retrieve a property form that node and append it to a string.

     

    List<Node> nodes = uQuery.GetNodesByXPath("//*[@id = '1343' or @id = '1103']//*");
                    int sort = 0;
                    foreach (Node item in nodes)
                    {          
    string propertyList = "";
    //Here is where I need help the rest is pseudo code
    List<ContentID> ids = Node.getProperty("NodePicker")
    foreach (ContentID id in ids) {
    Node newContent = new Node(id);
    propertyList += newContent.getProperty("associatedProperty").Value + ",";
    }
                     }

    Any help would be appreciated.

    Thanks!

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 03, 2012 @ 17:45
    Tom Fulton
    0

    Hi,

    Are you storing your MNTP values as XML or CSV?  If XML, something like this should work (not tested):

    (using uComponents.Core.uQueryExtensions)

                string nodesList = item.GetPropertyValue<string>("NodePicker");

                XmlDocument xd = new XmlDocument();
                xd.LoadXml(nodesList);
                foreach (XmlElement value in xd.SelectNodes("/MultiNodePicker/nodeId"))
                {
                    Node newContent = new Node(Convert.ToInt32(value.InnerText));
                    propertyList += newContent.GetPropertyValue<string>("associatedProperty");
                }

    -Tom

  • Tim 1193 posts 2675 karma points MVP 3x c-trib
    Jan 04, 2012 @ 12:54
    Tim
    0

    If you're storing as CSV, you can use something like:

                string[] nodesList = item.GetPropertyValue("NodePicker")<string>.Split(',');
    
                foreach (string value in nodesList)
                {
                    Node newContent = new Node(Convert.ToInt32(value));
                    propertyList += newContent.GetPropertyValue("associatedProperty");
                }
    
  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Mar 21, 2012 @ 08:30
    Hendy Racher
    0

    Hi,

    Sorry a bit late to aswer this, but thought I'd mention that uQuery also has methods to return node collections from the stored Xml / Csv values (in this case the "NodePicker"  property).

    List<Node> nodes = uQuery.GetNodesByXPath("//*[@id = '1343' or @id = '1103']//*");
    List<Node> pickedNodes;
    StringBuilder stringBuilder = new StringBuilder();

    foreach(Node node in nodes)
    {
    pickedNodes = uQuery.GetNodesByXml(node.GetProperty<string>("NodePicker");

    foreach (Node pickedNode in pickedNodes)
    {
    stringBuilder.Append(pickedNode.GetProperty<string>("associatedProperty") + ", ");
    }
    }

    If the MNTP is storing a csv, then:

    pickedNodes = uQuery.GetNodesByXml(node.GetProperty<string>("NodePicker");

    can be replaced with:

    pickedNodes = uQuery.GetNodesByCsv(node.GetProperty<string>("NodePicker)";

     

Please Sign in or register to post replies

Write your reply to:

Draft