本文整理汇总了C#中HtmlAgilityPack.HtmlDocument.CreateNavigator方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlAgilityPack.HtmlDocument.CreateNavigator方法的具体用法?C# HtmlAgilityPack.HtmlDocument.CreateNavigator怎么用?C# HtmlAgilityPack.HtmlDocument.CreateNavigator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack.HtmlDocument
的用法示例。
在下文中一共展示了HtmlAgilityPack.HtmlDocument.CreateNavigator方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getConfigFromFile
private static EnvironmentConfig getConfigFromFile(FileInfo fileInfo)
{
EnvironmentConfig cfg = new EnvironmentConfig();
cfg.FileInfo = fileInfo;
cfg.IsGuardServerAllowed = !System.Text.RegularExpressions.Regex.IsMatch(fileInfo.Name, "NoGS", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
cfg.Name = System.Text.RegularExpressions.Regex.Replace(fileInfo.Name, @"\.ttmd\.cfg", String.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
cfg.Name = System.Text.RegularExpressions.Regex.Replace(cfg.Name, @"\.NoGS", String.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
using (var reader = fileInfo.OpenRead())
{
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(reader);
var xpathNavi = doc.CreateNavigator();
var multicastNode = xpathNavi.SelectSingleNode("/ttmconfiguration[1]/multicastgroups[1]");
if (multicastNode != null && !String.IsNullOrEmpty(multicastNode.Value))
{
cfg.Multicast = multicastNode.Value.Replace("> =", String.Empty).Trim();
}
var daemonNode = xpathNavi.SelectSingleNode("/ttmconfiguration[1]/proxy[1]/daemon1[1]");
if (daemonNode != null && !String.IsNullOrEmpty(daemonNode.Value))
{
var regex = new System.Text.RegularExpressions.Regex(@"\d+\.\d+\.\d+\.\d+", System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Multiline);
var match = regex.Match(daemonNode.Value);
if (match.Success)
{
cfg.RemoteDaemon = match.Value;
cfg.Multicast = null;
}
}
}
return cfg;
}
示例2: ParseSaveAndFixImages
private static String ParseSaveAndFixImages(string contents, string dirPath)
{
contents = System.Web.HttpUtility.HtmlDecode(contents);
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(new StringReader(contents));
var nav = doc.CreateNavigator();
var strExpression = "//img";
HtmlAgilityPack.HtmlNodeCollection imgTags = doc.DocumentNode.SelectNodes(strExpression);
if (imgTags != null)
{
foreach (HtmlAgilityPack.HtmlNode tag in imgTags)
{
if (tag.Attributes["src"] != null)
{
String imgPath = tag.Attributes["src"].Value;
tag.Attributes["src"].Value = GetAndSaveImage(imgPath, dirPath);
}
}
}
string finalContents = null;
using (StringWriter sw = new StringWriter())
{
doc.Save(sw);
finalContents = sw.ToString();
}
return finalContents;
}
示例3: ParseChoices
private static List<Choice> ParseChoices(string choicesHtml)
{
choicesHtml = System.Web.HttpUtility.HtmlDecode(choicesHtml);
var choices = new List<Choice>();
/*
* <div id="room-choices"><h2>You have 4 choices:</h2>
* <ul class="choices">
* <li><a href="/story/choice.php?id=184898" title="184898,94419">Years later…</a></li>
* <li><a href="/story/choice.php?id=184899" title="184899,94416">The Empire (Lies)</a></li>
* <li><a href="/story/choice.php?id=184900" title="184900,94417">The Empire (Truth)</a></li>
* <li><a href="/story/choice.php?id=184901" title="184901,94418">The Eternal Program (Hope)</a></li>
* </ul>
* </div>
*/
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(new StringReader(choicesHtml));
var nav = doc.CreateNavigator();
var strExpression = "//a";
foreach (HtmlAgilityPack.HtmlNode link in doc.DocumentNode.SelectNodes(strExpression))
{
string titleValue = link.GetAttributeValue("title", null);
String[] titleSplit = titleValue.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
Choice choice = new Choice(titleSplit[0], titleSplit[1], link.InnerHtml);
choices.Add(choice);
}
return choices;
}
示例4: go_button_Click
private void go_button_Click(object sender, EventArgs e)
{
ProgressDialog d = new ProgressDialog();
string character_path = character_box.Text;
string macro_path = macro_box.Text;
List<PowerInfo> powers = new List<PowerInfo>();
Dictionary<string, int> skills = new Dictionary<string, int>();
System.Text.RegularExpressions.Regex img_remover = new System.Text.RegularExpressions.Regex(@"<img.*?>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
// save the value of the checkbox
m_use_compendium = compendium_check.Checked;
d.AddTask((progress) =>
{
progress.Update("Scanning character sheet...");
using (FileStream fs = File.OpenRead(character_path))
{
XPathDocument doc = new XPathDocument(fs);
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator power_iter, weapon_iter;
// select all power nodes
power_iter = nav.Select("/D20Character/CharacterSheet/PowerStats/Power");
// update the progress steps
progress.Update(0, power_iter.Count);
// iterate them
while (power_iter.MoveNext())
{
string name;
string action_type;
List<string> compendium_info = new List<string>();
PowerUsage usage;
XPathNavigator power_url_nav = null;
try
{
// read the basic stuff
name = power_iter.Current.SelectSingleNode("@name").Value;
usage = Util.EnumParse<PowerUsage>(power_iter.Current.SelectSingleNode("specific[@name = 'Power Usage']").Value.Replace("-", ""));
action_type = power_iter.Current.SelectSingleNode("specific[@name = 'Action Type']").Value.Trim();
// get the url for the power in the compendium
if (m_use_compendium)
power_url_nav = nav.SelectSingleNode("//RulesElementTally/RulesElement[@name = \"" + name + "\"]/@url");
// ...and if we did that, pull down the power description
if (power_url_nav != null)
{
HtmlAgilityPack.HtmlDocument scraper_doc = new HtmlAgilityPack.HtmlDocument();
HtmlAgilityPack.HtmlNodeNavigator scraper_result;
XPathNodeIterator content_iter;
XPathNavigator scraper_nav = null;
// slurp
try
{
using (Stream s = m_compendium.GetEntryByUrl(power_url_nav.Value))
{
scraper_doc.Load(s, new UTF8Encoding());
scraper_nav = scraper_doc.CreateNavigator();
}
}
catch (Exception ex)
{
// if the user clicked cancel, stop attempting compendium stuff
if (ex is ApplicationException && ex.Message.ToLowerInvariant().Contains("user refused"))
m_use_compendium = false;
else
MessageBox.Show(ex.ToString(), "Compendium Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
// if the web request succeeded...
if (scraper_nav != null)
{
// select all the detail p tags
content_iter = scraper_nav.Select("//div[@id = 'detail']/p");
// loop through them
while (content_iter.MoveNext())
{
string line;
// cast to HtmlNodeNavigator
scraper_result = content_iter.Current as HtmlAgilityPack.HtmlNodeNavigator;
// skip publishing stuff
if (scraper_result == null || scraper_result.CurrentNode.InnerHtml.ToLowerInvariant().Contains("published in"))
continue;
// grab the line, strip images, and remove [] stuff
line = scraper_result.CurrentNode.InnerHtml;
line = img_remover.Replace(line, "-");
line = line.Replace("[W]", "<i>W</i>");
// add the line
compendium_info.Add(line);
}
//.........这里部分代码省略.........