void WriteCategory(TemplateCategoryViewModel category)
        {
            writer.WriteStartElement("Category");

            writer.WriteAttributeString("id", GetAttributeValueOrDefault(category.Id, "id"));
            writer.WriteAttributeString("name", GetAttributeValueOrDefault(category.Name, "Category"));

            foreach (TemplateCategoryViewModel childCategory in category.GetChildCategories())
            {
                WriteCategory(childCategory);
            }

            writer.WriteEndElement();
        }
        static void MarkNewCategories(TemplateCategoryViewModel category, IEnumerable <TemplateCategoryViewModel> categories)
        {
            var existingTopLevelCategory = category.FindExistingCategory(categories);

            if (existingTopLevelCategory != null)
            {
                foreach (var secondLevelCategory in category.GetChildCategories())
                {
                    var existingSecondLevelCategory = secondLevelCategory.FindExistingCategory(
                        existingTopLevelCategory.Categories);
                    if (existingSecondLevelCategory != null)
                    {
                        foreach (var newThirdLevelCategory in secondLevelCategory.GetChildCategories())
                        {
                            var existingThirdLevelCategory = newThirdLevelCategory.FindExistingCategory(
                                existingSecondLevelCategory.Categories);
                            if (existingThirdLevelCategory != null)
                            {
                                // Category exists.
                            }
                            else
                            {
                                newThirdLevelCategory.IsNew = true;
                            }
                        }
                    }
                    else
                    {
                        secondLevelCategory.IsNew = true;
                    }
                }
            }
            else
            {
                category.IsNew = true;
            }
        }