// 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); } }
// 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 { // } } }