Code Examples‎ > ‎HV2 API Explore‎ > ‎

TOC

On the TOC page enter a Topic ID (-1 for the virtual top level node), select the type of TOC data to return, and click "Get TOC Data". 

The list will fill with topic results. To the right is displayed Topic details for the selected topic result.




The dropdown contains a full table of contents that you can expand and drill into.

Table Of Contents

A HV2 table of contents can contain millions of items, so we build it incrementally as TreeView nodes are expanded. To get the the [+] gadget to appear on unexpanded nodes we add a dummy node under the unexpanded node. The TOC is hosted in a UserControl which we parent into the Content navigation tab. When you click a TOC node item there is a call back to ping a handler in the main form code. You can explore the code at your leisure.

Here are the main HV2 API calls for building a TOC.

This gives us the root nodes of the TOC.

ITopicCollection topics = _catalogRead.GetTableOfContents(_catalog, "-1", null, TocReturnDetail.TocRootNodes);

Call this when an unexplored node is expanded for the first time.
It gives us the immediate children of a particular topic.

ITopicCollection topics = _catalogRead.GetTableOfContents(_catalog, topic.Id, null, TocReturnDetail.TocChildren);

And that's all we really need to build a TOC.

The GetTableOfContents() method returns a collections of Topic objects, according to the parameters passed in. 
  • Parameter 1: An open catalog object (we created that in the Catalog.Open() call).
  • Parameter 2: A topic ID (not applicable in the TocRootNodes call). Use "-1" to represent the TOC root node.
  • Parameter 3: A Filter which is a list of Name\Value pairs. We are not using filters in this demo. We want the full TOC so we pass null (no filtering).
  • Parameter 4: Specifies the type of TOC info we want returned (see TocReturnDetail enum).

TocReturnDetail enum

TocReturnDetail.TocAncestors   returns a list of parent topics of the specified node up to the root.
TocReturnDetail.TocChildren   returns a list of child topics of the specified node.
TocReturnDetail.TocDescendants   returns a list of every topic under the specified node. 
TocReturnDetail.TocRootNodes   returns a list of all level 0 nodes (children of TopicID="-1").
TocReturnDetail.TocSiblings   returns a list of all nodes at the same level with the same parent. 

Topic class

ITopicCollection is a collection of Topic objects. Here we are getting all Topics from the collection. 

ITopicCollection topics = _catalogRead.GetTableOfContents(_catalog, "-1", null, TocReturnDetail.TocRootNodes);

for (int i = 0; i < topics.Count; i++)
{
    topics.MoveTo(i);
    Topic topic = (Topic) topics.Current;
    ....
}

There is also topics.MoveNext(); that can be used if you are iterating with a foreach(...) { }  loop.

The Topic class has very handy members. Here an example of the contents:

topic.Category                
topic.ContentFilter            Visual F#
topic.ContentType              Reference
topic.Description              Returns a string by concatenating...
topic.DisplayVersion          
topic.Id                       489CF6E9-E0A0-457A-9E9B-BF630A40A25B
topic.Locale                   en-US
topic.Package                  Visual_Studio_21800792_VS_100_en-us_1.mshc;\R402.htm
topic.ParentId                 A5FDA9CD-D71F-4271-A6A4-AB4CAA0BE550
topic.TableOfContentsHasChildren False
topic.TableOfContentsPosition  10
topic.Title                    String.replicate Function (F#)
topic.TopicLocale              EN-US
topic.TopicVersion             100
topic.Url                      Visual_Studio_21800792_VS_100_en-us_1.mshc;\R402.htm
topic.Vendor                   Microsoft

Note especially...
  • topic.TableOfContentsHasChildren tells us if we can expand the node.
  • topic.Title gives us the node text.
  • topic.ParentId gives us the topic ID of the topics patent topic in the TOC.
Comments