示例#1
0
 // Parse the metadata from the given element?
 private void ParseMetaCategories(DitaElement parentElement)
 {
     try
     {
         List <DitaElement> categoriesData = parentElement?.FindChildren("category");
         if (categoriesData != null)
         {
             foreach (DitaElement categoryData in categoriesData)
             {
                 foreach (DitaElement data in categoryData.Children)
                 {
                     if (data?.Attributes.ContainsKey("name") ?? false)
                     {
                         if (BookMeta.ContainsKey(data?.Attributes["name"]))
                         {
                             Trace.TraceWarning($"BookMeta already contains a value for {data?.Attributes["name"]}");
                         }
                         else
                         {
                             BookMeta.Add(data?.Attributes["name"], data?.Attributes["value"]);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Trace.TraceError(ex);
     }
 }
示例#2
0
        // Tries to add the text of the given element to the dictionary
        private bool AddChildDitaElementTextToDictionary(DitaElement parentElement, string type,
                                                         Dictionary <string, string> dictionary)
        {
            // Try to find the child elements that match the type
            List <DitaElement> childElements = parentElement.FindChildren(type);

            if (childElements?.Count > 0)
            {
                foreach (DitaElement childElement in childElements)
                {
                    dictionary.Add(type, childElement.InnerText);
                }

                return(true);
            }

            return(false);
        }
示例#3
0
        // Parse the version of the document
        private void ParseBookMapVersion(DitaElement bookMetaElement)
        {
            // Try checking the publisher information section
            DitaElement publisherInformationElement = bookMetaElement?.FindOnlyChild("publisherinformation");
            DitaElement publishedElement            = publisherInformationElement?.FindChildren("published")?.Last();
            DitaElement revisionIdElement           = publishedElement?.FindOnlyChild("revisionid");
            string      version = revisionIdElement?.ToString();

            // Try checking the prodinfo section
            if (string.IsNullOrWhiteSpace(version) || version == "ProductVersionNumber")
            {
                DitaElement prodinfoElement = bookMetaElement?.FindOnlyChild("prodinfo");
                DitaElement vrmlistElement  = prodinfoElement?.FindOnlyChild("vrmlist");
                DitaElement vrmElement      = vrmlistElement?.FindChildren("vrm")?[0];
                version = vrmElement?.Attributes?["version"];
            }

            if (!string.IsNullOrWhiteSpace(version))
            {
                BookMeta.Add("version", version);
            }
        }
示例#4
0
        // Parse the date of the document
        private void ParseBookMapReleaseDate(DitaElement bookMetaElement)
        {
            DitaElement publisherInformationElement = bookMetaElement?.FindOnlyChild("publisherinformation");
            DitaElement publishedElement            = publisherInformationElement?.FindChildren("published")?.Last();
            DitaElement completedElement            = publishedElement?.FindOnlyChild("completed");
            string      year  = completedElement?.FindOnlyChild("year")?.ToString();
            string      month = completedElement?.FindOnlyChild("month")?.ToString();
            string      day   = completedElement?.FindOnlyChild("day")?.ToString();

            if (!string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month) && !string.IsNullOrWhiteSpace(day))
            {
                try
                {
                    // Is this a valid date?
                    DateTime publishDate = new DateTime(int.Parse(year), int.Parse(month), int.Parse(day));
                    BookMeta.Add("published date", $"{publishDate.Day}/{publishDate.Month}/{publishDate.Year} 00:00:00");
                }
                catch
                {
                    //
                }
            }
        }