开发者

Iterate over Umbraco getAllTagsInGroup result

I'm trying to get a list of tags from a particular tag group in Umbraco (v4.0.2.1) using the following code:

var tags = umbraco.editorControls.tags.library.getAllTagsInGroup("document downloads");

What I want to do is just output a list of those tags. However, if I output the variable 'tags' it just outputs a list of all tags in a string. I want to split each tag o开发者_运维百科nto a new line.

When I check the datatype of the 'tags' variable:

string tagType = tags.GetType().ToString();

...it outputs MS.Internal.Xml.XPath.XPathSelectionIterator.

So question is, how do I get the individual tags out of the 'tags' variable? How do I work with a variable of this data type? I can find examples of how to do it by loading an actual XML file, but I don't have an actual XML file - just the 'tags' variable to work with.

Thanks very much for any help!

EDIT1: I guess what I'm asking is, how do I loop through the nodes returned by an XPathSelectionIterator data type?

EDIT2: I've found this code, which almost does what I need:

        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 it expects the URL of an actual XML file to load into the first line. My XML file is essentially the 'tags' variable, not an actual XML file. So when I replace:

XPathDocument document = new XPathDocument("file.xml");

...with:

XPathDocument document = new XPathDocument(tags);

...it just errors.


Since it is an Iterator, I would suggest you iterate it. ;-)

var tags = umbraco.editorControls.tags.library.getAllTagsInGroup("document downloads");

foreach (XPathNavigator tag in tags) {
  // handle current tag
}


I think this does the trick a little better.

The problem is that getAllTagsInGroup returns the container for all tags, you need to get its children.

foreach( var tag in umbraco.editorControls.tags.library.getAllTagsInGroup("category").Current.Select("/tags/tag") )
{
     /// Your Code
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜