本文整理汇总了C#中Bloom.Book.HtmlDom.SafeSelectNodes方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlDom.SafeSelectNodes方法的具体用法?C# HtmlDom.SafeSelectNodes怎么用?C# HtmlDom.SafeSelectNodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bloom.Book.HtmlDom
的用法示例。
在下文中一共展示了HtmlDom.SafeSelectNodes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyImageMetadataToWholeBook
public static void CopyImageMetadataToWholeBook(string folderPath, HtmlDom dom, Metadata metadata, IProgress progress)
{
progress.WriteStatus("Starting...");
//First update the images themselves
int completed = 0;
var imgElements = GetImagePaths(folderPath);
foreach (string path in imgElements)
{
progress.ProgressIndicator.PercentCompleted = (int)(100.0 * (float)completed / imgElements.Count());
progress.WriteStatus("Copying to " + Path.GetFileName(path));
using (var image = PalasoImage.FromFile(path))
{
image.Metadata = metadata;
image.SaveUpdatedMetadataIfItMakesSense();
}
++completed;
}
//Now update the html attributes which echo some of it, and is used by javascript to overlay displays related to
//whether the info is there or missing or whatever.
foreach (XmlElement img in dom.SafeSelectNodes("//img"))
{
UpdateImgMetdataAttributesToMatchImage(folderPath, img, progress, metadata);
}
}
示例2: CopyImageMetadataToWholeBook
public static void CopyImageMetadataToWholeBook(string folderPath, HtmlDom dom, Metadata metadata, IProgress progress)
{
progress.WriteStatus("Starting...");
//First update the images themselves
int completed = 0;
var imgElements = GetImagePaths(folderPath);
foreach (string path in imgElements)
{
progress.ProgressIndicator.PercentCompleted = (int)(100.0 * (float)completed / imgElements.Count());
progress.WriteStatus("Copying to " + Path.GetFileName(path));
try
{
metadata.WriteIntellectualPropertyOnly(path);
}
catch (TagLib.CorruptFileException e)
{
NonFatalProblem.Report(ModalIf.Beta, PassiveIf.All,"Image metadata problem", "Bloom had a problem accessing the metadata portion of this image " + path+ " ref(BL-3214)", e);
}
++completed;
}
//Now update the html attributes which echo some of it, and is used by javascript to overlay displays related to
//whether the info is there or missing or whatever.
foreach (XmlElement img in dom.SafeSelectNodes("//img"))
{
UpdateImgMetdataAttributesToMatchImage(folderPath, img, progress, metadata);
}
}
示例3: UpdateBook
public static void UpdateBook(HtmlDom dom, string language1Iso639Code)
{
int page = 0;
foreach (XmlElement pageDiv in dom.SafeSelectNodes("/html/body//div[contains(@class,'bloom-page')]"))
{
var term = pageDiv.SelectSingleNode("//div[contains(@data-book,'term')]").InnerText.Trim();
XmlNode weekDataNode = pageDiv.SelectSingleNode("//div[contains(@data-book,'week')]");
if(weekDataNode==null)
continue; // term intro books don't have weeks
var week = weekDataNode.InnerText.Trim();
// TODO: need a better way to identify thumbnails, like a class that is always there, lest we replace some other img that we don't want to replace
foreach (XmlElement thumbnailContainer in pageDiv.SafeSelectNodes(".//img"))
{
++page;
thumbnailContainer.SetAttribute("src", language1Iso639Code + "-t" + term + "-w" + week + "-p" + page + ".png");
}
}
}
示例4: UpdateBook
//TODO: make this be a real extension
public static void UpdateBook(HtmlDom dom, string language1Iso639Code)
{
int day = 0;
foreach (XmlElement pageDiv in dom.SafeSelectNodes("/html/body/div[contains(@class,'bloom-page')]"))
{
var term = pageDiv.SelectSingleNode("//div[contains(@data-book,'term')]").InnerText.Trim();
var week = pageDiv.SelectSingleNode("//div[contains(@data-book,'week')]").InnerText.Trim();
var thumbnailHolders = pageDiv.SafeSelectNodes(".//img");
if (thumbnailHolders.Count == 2)
{
++day;
((XmlElement)thumbnailHolders[0]).SetAttribute("src", language1Iso639Code+"-t"+term + "-w" + week + "-d" + day + ".png");
++day;
((XmlElement)thumbnailHolders[1]).SetAttribute("src", language1Iso639Code + "-t" + term + "-w" + week + "-d" + day + ".png");
}
//day1Thumbnail day2Thumbnail day4Thumbnail
//unfortunately Day3 went out with an img container just copied from day1, with erroneous "day1Thumbnail" class
}
}
示例5: CopyStyleSheets
private void CopyStyleSheets(HtmlDom pageDom)
{
foreach (XmlElement link in pageDom.SafeSelectNodes("//link[@rel='stylesheet']"))
{
var href = Path.Combine(Book.FolderPath, link.GetAttribute("href"));
var name = Path.GetFileName(href);
if (name == "fonts.css")
continue; // generated file for this book, already copied to output.
var fl = Storage.GetFileLocator();
//var path = this.GetFileLocator().LocateFileWithThrow(name);
var path = fl.LocateFileWithThrow(name);
CopyFileToEpub(path);
}
}
示例6: UpdateStyleSheetLinkPaths
// /// <summary>
// /// Creates a relative path from one file or folder to another.
// /// </summary>
// /// <param name="fromPath">Contains the directory that defines the start of the relative path.</param>
// /// <param name="toPath">Contains the path that defines the endpoint of the relative path.</param>
// /// <param name="dontEscape">Boolean indicating whether to add uri safe escapes to the relative path</param>
// /// <returns>The relative path from the start directory to the end path.</returns>
// /// <exception cref="ArgumentNullException"></exception>
// public static String MakeRelativePath(String fromPath, String toPath)
// {
// if (String.IsNullOrEmpty(fromPath)) throw new ArgumentNullException("fromPath");
// if (String.IsNullOrEmpty(toPath)) throw new ArgumentNullException("toPath");
//
// //the stuff later on needs to see directory names trailed by a "/" or "\".
// fromPath = fromPath.Trim();
// if (!fromPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
// {
// if (Directory.Exists(fromPath))
// {
// fromPath = fromPath + Path.DirectorySeparatorChar;
// }
// }
// Uri fromUri = new Uri(fromPath);
// Uri toUri = new Uri(toPath);
//
// Uri relativeUri = fromUri.MakeRelativeUri(toUri);
// String relativePath = Uri.UnescapeDataString(relativeUri.ToString());
//
// return relativePath.Replace('/', Path.DirectorySeparatorChar);
// }
private void UpdateStyleSheetLinkPaths(HtmlDom dom, IFileLocator fileLocator, IProgress log)
{
foreach (XmlElement linkNode in dom.SafeSelectNodes("/html/head/link"))
{
var href = linkNode.GetAttribute("href");
if (href == null)
{
continue;
}
//TODO: see long comment on ProjectContextGetFileLocations() about linking to the right version of a css
//TODO: what cause this to get encoded this way? Saw it happen when creating wall calendar
href = href.Replace("%5C", "/");
var fileName = Path.GetFileName(href);
if (!fileName.StartsWith("xx")) //I use xx as a convenience to temporarily turn off stylesheets during development
{
var path = fileLocator.LocateOptionalFile(fileName);
//we want these stylesheets to come from the book folder
if (string.IsNullOrEmpty(path)|| path.Contains("languageDisplay.css"))
{
//look in the same directory as the book
var local = Path.Combine(_folderPath, fileName);
if (File.Exists(local))
path = local;
}
//we want these stylesheets to come from the user's collection folder, not ones found in the templates directories
else if (path.Contains("CollectionStyles.css")) //settingsCollectionStyles & custonCollectionStyles
{
//look in the parent directory of the book
var pathInCollection = Path.Combine(Path.GetDirectoryName(_folderPath), fileName);
if (File.Exists(pathInCollection))
path = pathInCollection;
}
if (!string.IsNullOrEmpty(path))
{
//this is here for geckofx 11... probably can remove it when we move up to modern gecko, as FF22 doesn't like it.
linkNode.SetAttribute("href", "file://" + path);
}
else
{
throw new ApplicationException(string.Format("Bloom could not find the stylesheet '{0}', which is used in {1}", fileName, _folderPath));
}
}
}
}
示例7: EnsureHasLinkToStyleSheet
private void EnsureHasLinkToStyleSheet(HtmlDom dom, string path)
{
foreach (XmlElement link in dom.SafeSelectNodes("//link[@rel='stylesheet']"))
{
var fileName = link.GetStringAttribute("href");
if (fileName == path)
return;
}
dom.AddStyleSheet(path);
}
示例8: RemoveExistingXMatter
/// <summary>
///remove any x-matter in the book
/// </summary>
public static void RemoveExistingXMatter(HtmlDom dom)
{
foreach (XmlElement div in dom.SafeSelectNodes("//div[contains(@class,'bloom-frontMatter') or contains(@class,'bloom-backMatter')]"))
{
div.ParentNode.RemoveChild(div);
}
}
示例9: EnsureDoesntHaveLinkToStyleSheet
private void EnsureDoesntHaveLinkToStyleSheet(HtmlDom dom, string path)
{
foreach (XmlElement link in dom.SafeSelectNodes("//link[@rel='stylesheet']"))
{
var fileName = link.GetStringAttribute("href");
if (fileName == path)
dom.RemoveStyleSheetIfFound(path);
}
}
示例10: GetLayoutChoices
public static IEnumerable<Layout> GetLayoutChoices(HtmlDom dom, IFileLocator fileLocator)
{
//here we walk through all the stylesheets, looking for one with the special style which tells us which page/orientations it supports
foreach (XmlElement link in dom.SafeSelectNodes("//link[@rel='stylesheet']"))
{
var fileName = link.GetStringAttribute("href");
if (fileName.ToLower().Contains("mode") || fileName.ToLower().Contains("page") ||
fileName.ToLower().Contains("matter") || fileName.ToLower().Contains("languagedisplay"))
continue;
fileName = fileName.Replace("file://", "").Replace("%5C", "/");
var path = fileLocator.LocateFile(fileName);
if(string.IsNullOrEmpty(path))
{
throw new ApplicationException("Could not locate "+fileName);
}
var contents = File.ReadAllText(path);
var start = contents.IndexOf("STARTLAYOUTS");
if (start < 0)
continue; //yield break; // continue;//move on to the next stylesheet
start += "STARTLAYOUTS".Length;
var end = contents.IndexOf("ENDLAYOUTS",start);
var s = contents.Substring(start, end - start);
IEnumerable<Layout> layouts = null;
try
{
layouts = Layout.GetConfigurationsFromConfigurationOptionsString(s);
}
catch (Exception e)
{
throw new ApplicationException("Problem parsing the 'layouts' comment of " + fileName + ". The contents were\r\n" + s, e);
}
foreach (var p in layouts)
{
yield return p;
}
yield break;
}
//default to A5Portrait
yield return new Layout {SizeAndOrientation = FromString("A5Portrait")};
}
示例11: HtmlHasLockedDownFlag
public static bool HtmlHasLockedDownFlag(HtmlDom dom)
{
var node = dom.SafeSelectNodes(String.Format("//meta[@name='lockedDownAsShell' and @content='true']"));
return node.Count > 0;
}
示例12: UpdatePageFromFactoryTemplates
private void UpdatePageFromFactoryTemplates(HtmlDom bookDom, IProgress progress)
{
var originalLayout = Layout.FromDom(bookDom, Layout.A5Portrait);
var templatePath = BloomFileLocator.GetFactoryBookTemplateDirectory( "Basic Book");
var templateDom = XmlHtmlConverter.GetXmlDomFromHtmlFile(templatePath.CombineForPath("Basic Book.html"), false);
progress.WriteStatus("Updating pages that were based on Basic Book...");
foreach (XmlElement templatePageDiv in templateDom.SafeSelectNodes("//body/div"))
{
if (templatePageDiv.GetOptionalStringAttribute("class", "").Contains("customPage"))
continue; // we sure don't want to revert this page to its blank custom state
var templateId = templatePageDiv.GetStringAttribute("id");
if (string.IsNullOrEmpty(templateId))
continue;
var templatePageClasses = templatePageDiv.GetAttribute("class");
//note, lineage is a series of guids separated by a semicolon
foreach (XmlElement pageDiv in bookDom.SafeSelectNodes("//body/div[contains(@data-pagelineage, '" + templateId + "')]"))
{
pageDiv.SetAttribute("class", templatePageClasses);
//now for all the editable elements within the page
int count = 0;
foreach (XmlElement templateElement in templatePageDiv.SafeSelectNodes("div/div"))
{
UpdateDivInsidePage(count, templateElement, pageDiv, progress);
++count;
}
}
}
//custom layout gets messed up when we copy classes over from, for example, Basic Book
SetLayout(originalLayout);
//Likewise, the multilingual settings (e.g. bloom-bilingual) get messed up, so restore those
UpdateMultilingualSettings(bookDom);
}
示例13: UpdateEditableAreasOfElement
/// <summary>
/// This is called both for the whole book, and for individual pages when the user uses Origami to make changes to the layout of the page.
/// It would be nicer in the HtmlDom, but it uses knowledge about the collection and book languages that the DOM doesn't have.
/// </summary>
/// <param name="elementToUpdate"></param>
public void UpdateEditableAreasOfElement(HtmlDom dom)
{
var language1Iso639Code = _collectionSettings.Language1Iso639Code;
var multilingualContentLanguage2 = _bookData.MultilingualContentLanguage2;
var multilingualContentLanguage3 = _bookData.MultilingualContentLanguage3;
foreach (XmlElement div in dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]"))
{
TranslationGroupManager.PrepareElementsInPageOrDocument(div, _collectionSettings);
TranslationGroupManager.UpdateContentLanguageClasses(div, _collectionSettings, language1Iso639Code, multilingualContentLanguage2, multilingualContentLanguage3);
}
}
示例14: GetLayoutChoices
public static IEnumerable<Layout> GetLayoutChoices(HtmlDom dom, IFileLocator fileLocator)
{
//here we walk through all the stylesheets, looking for one with the special style which tells us which page/orientations it supports
foreach (XmlElement link in dom.SafeSelectNodes("//link[@rel='stylesheet']"))
{
var fileName = link.GetStringAttribute("href");
if (fileName.ToLowerInvariant().Contains("mode") || fileName.ToLowerInvariant().Contains("page") ||
fileName.ToLowerInvariant().Contains("matter") || fileName.ToLowerInvariant().Contains("languagedisplay"))
continue;
fileName = fileName.Replace("file://", "").Replace("%5C", "/").Replace("%20", " ");
var path = fileLocator.LocateFile(fileName);
if(string.IsNullOrEmpty(path))
{
// We're looking for a block of json that is typically found in Basic Book.css or a comparable place for
// a book based on some other template. Caling code is prepared for not finding this block.
// It seems safe to ignore a reference to some missing style sheet.
NonFatalProblem.Report(ModalIf.None, PassiveIf.Alpha, "Could not find " + fileName+" while looking for size choices");
continue;
}
var contents = RobustFile.ReadAllText(path);
var start = contents.IndexOf("STARTLAYOUTS");
if (start < 0)
continue; //yield break; // continue;//move on to the next stylesheet
start += "STARTLAYOUTS".Length;
var end = contents.IndexOf("ENDLAYOUTS",start);
var s = contents.Substring(start, end - start);
IEnumerable<Layout> layouts = null;
try
{
layouts = Layout.GetConfigurationsFromConfigurationOptionsString(s);
}
catch (Exception e)
{
throw new ApplicationException("Problem parsing the 'layouts' comment of " + fileName + ". The contents were\r\n" + s, e);
}
foreach (var p in layouts)
{
yield return p;
}
yield break;
}
//default to A5Portrait
yield return new Layout {SizeAndOrientation = FromString("A5Portrait")};
}
示例15: EnsureIdsAreUnique
private static void EnsureIdsAreUnique(HtmlDom dom, string elementTag, List<string> ids, StringBuilder builder)
{
foreach(XmlElement element in dom.SafeSelectNodes("//" + elementTag + "[@id]"))
{
var id = element.GetAttribute("id");
if(ids.Contains(id))
builder.AppendLine("The id of this " + elementTag + " must be unique, but is not: " + element.OuterXml);
else
ids.Add(id);
}
}