private void ReadTopic(XmlReader reader, BuildTopicTocInfo parent)
        {
            XmlNodeType nodeType = XmlNodeType.None;

            while (reader.Read())
            {
                nodeType = reader.NodeType;
                if (nodeType == XmlNodeType.Element && String.Equals(reader.Name, "topic",
                                                                     StringComparison.OrdinalIgnoreCase))
                {
                    string topicId        = reader.GetAttribute("id");
                    string topicFile      = reader.GetAttribute("file");
                    string topicContainer = reader.GetAttribute("project");
                    if (!String.IsNullOrEmpty(topicId) &&
                        !String.IsNullOrEmpty(topicFile))
                    {
                        BuildTopicTocInfo topic = new BuildTopicTocInfo(
                            topicId, topicFile, parent);
                        topic.Container = topicContainer;

                        if (String.Equals(topicContainer, "_Namespaces",
                                          StringComparison.OrdinalIgnoreCase))
                        {
                            _listNamespaces.Add(topic);
                        }

                        parent.Add(topic);

                        if (!reader.IsEmptyElement)
                        {
                            // Read the sub-topics...
                            this.ReadTopic(reader, topic);
                        }
                    }
                }
                else if (nodeType == XmlNodeType.EndElement)
                {
                    if (String.Equals(reader.Name, BuildTopicTocInfo.TagName,
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }
            }
        }
        private void CustomMergeToc(BuildTopicTocInfo topicParent, TocItem tocItem)
        {
            TocItemSourceType sourceType = tocItem.SourceType;

            if (sourceType == TocItemSourceType.None)
            {
                return;
            }

            IBuildNamedList <BuildGroupTocInfo> groupTocItems = _tocContext.Items;
            BuildGroupTocInfo groupToc = null;
            BuildTopicTocInfo tocInfo  = null;

            switch (sourceType)
            {
            case TocItemSourceType.None:
                break;

            case TocItemSourceType.Group:
                groupToc = groupTocItems[tocItem.SourceId];
                Debug.Assert(groupToc != null);
                break;

            case TocItemSourceType.Namespace:
                tocInfo = _tocContext[tocItem.SourceId];
                break;

            case TocItemSourceType.NamespaceRoot:
                groupToc = groupTocItems[tocItem.SourceId];
                Debug.Assert(groupToc != null);
                if (groupToc != null)
                {
                    if (groupToc.IsRooted)
                    {
                        tocInfo = groupToc[0];
                    }
                    else
                    {
                        throw new BuildException(
                                  "The specified reference group does not have a root container.");
                    }
                    groupToc = null;
                }
                break;

            case TocItemSourceType.Topic:
                tocInfo = _tocContext[tocItem.SourceId];
                break;
            }

            if (groupToc != null)
            {
                if (!groupToc.Exclude)
                {
                    topicParent.AddRange(groupToc.Items);
                }
                return;
            }

            if (tocInfo == null)
            {
                if (_logger != null)
                {
                    _logger.WriteLine(String.Format(
                                          "The TOC topic for the item '{0}' cannot be found.", tocItem.Name),
                                      BuildLoggerLevel.Warn);
                }

                return;
            }

            BuildTopicTocInfo topicToc = null;

            if (tocItem.SourceRecursive)
            {
                topicToc = tocInfo;
            }
            else
            {
                topicToc = new BuildTopicTocInfo(tocInfo.Name,
                                                 tocInfo.Source, topicParent);
                topicToc.Container = tocInfo.Container;
            }

            topicParent.Add(topicToc);

            for (int j = 0; j < tocItem.ItemCount; j++)
            {
                this.CustomMergeToc(topicToc, tocItem[j]);
            }
        }