Copied to clipboard

Flag this post as spam?

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


  • Dan 1288 posts 3921 karma points c-trib
    Nov 29, 2010 @ 10:53
    Dan
    0

    Getting individual tags from getAllTagsInGroup('abc')

    Hi,

    I'm working on a 4.0.2.1 installation, and am trying to build a string in a Base method using getAllTagsInGroup.  The code I have is this:

    var tags = umbraco.editorControls.tags.library.getAllTagsInGroup("document downloads");
    foreach (var tag in tags)
    {
        debugString += tag.ToString().ToLower() + " <br /> ";
    }

    When I output 'debugString' it outputs ALL tags in the group for each iteration.  So it loops through all 50+ tags in the group, but outputs all of the tags each time, so I end up with 50 identical lines of text - each made up of all the tags in the group joined together.

    Can anyone see how to correct this?

    Thanks

  • Dan 1288 posts 3921 karma points c-trib
    Nov 29, 2010 @ 13:19
    Dan
    0

    I think this is something to do with umbraco.editorControls.tags.library.getAllTagsInGroup returning the full XML for the tags, rather than an array of tags as I'd thought it would.

    Does anyone know where the tags XML is stored, or are tags not stored in their own XML file and just pulled directly from the database in the Umbraco UI, then saved in the umbraco.config XML file?  Does anyone know how to get the individual tags out of the 'tags' variable above?

  • Dan 1288 posts 3921 karma points c-trib
    Nov 29, 2010 @ 16:35
    Dan
    0

    Okay, after a bit of digging I found some documentation which describes the 'getAllTagsInGroup' method.

    So how do I deal with a data type of XPathNodeIterator type in order to iterate through the nodes?

    I know it's possible to do this:

    XPathDocument document = new XPathDocument("file.xml");
            XPathNavigator navigator = document.CreateNavigator();
            XPathNodeIterator nodes = navigator.Select("/tags/tag");
            nodes.MoveNext();
            XPathNavigator nodesNavigator = nodes.Current;
            XPathNodeIterator nodesText = nodesNavigator.SelectDescendants(XPathNodeType.Text, false);
            while (nodesText.MoveNext())
                debugString += nodesText.Current.Value.ToString();

    But when I replace XPathDocument("file.xml") with XPathDocument(tags) it errors:

    cannot convert from 'System.Xml.XPath.XPathNodeIterator' to 'System.Xml.XmlReader'

    Any ideas very much appreciated folks!

  • Dan 1288 posts 3921 karma points c-trib
    Nov 29, 2010 @ 21:27
    Dan
    1

    Got it!

               XPathNodeIterator tags = umbraco.editorControls.tags.library.getAllTagsInGroup("document downloads");
    XPathNavigator allTags = tags.Current;
    XPathNodeIterator nodes = allTags.Select("tags/tag");

    foreach (XPathNavigator node in nodes)
    {
    debugString += node.ToString().ToLower() + "<br />";
    }
Please Sign in or register to post replies

Write your reply to:

Draft