本文整理汇总了C#中HtmlAgilityPack.HtmlNode.AppendChild方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlNode.AppendChild方法的具体用法?C# HtmlNode.AppendChild怎么用?C# HtmlNode.AppendChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack.HtmlNode
的用法示例。
在下文中一共展示了HtmlNode.AppendChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddContentRegions
private static void AddContentRegions(Dictionary<string, HtmlNode> contentNodes, HtmlNode bodyNode)
{
foreach (var contentNode in contentNodes)
{
var titleNode = CreateContentTitleNode(contentNode);
var linkNode = CreateContentLinkNode(titleNode);
var headerNode = CreateContentHeaderNode(linkNode);
bodyNode.AppendChild(headerNode);
}
}
示例2: AddImageNode
public void AddImageNode(HtmlDocument htmlDoc,HtmlNode new_node,string image_source)
{
//<img src=\"{1}\" style=\"height:100%;width:100%;\"/>
HtmlNode image_node = htmlDoc.CreateElement("img");
HtmlAttribute src_attr = htmlDoc.CreateAttribute("src", image_source);
image_node.Attributes.Append(src_attr);
HtmlAttribute style_attr = htmlDoc.CreateAttribute("style", "height:100%;width:100%;");
image_node.Attributes.Append(style_attr);
new_node.AppendChild(image_node);
}
示例3: TransformHtml
public override void TransformHtml(Generator generator, Drawable element, HtmlNode node)
{
var document = node.OwnerDocument;
var gridContainer = document.CreateElement("div");
var style = element.Style;
// TODO: Move this to GeneratorBlock
if (style != null)
gridContainer.Attributes.Add(document.CreateAttribute("class", style));
// Add our created element to the parent.
node.AppendChild(gridContainer);
// IMPORTANT: Unless you know better, always call this at the end. Otherwise the Content of this
// node will NOT be turned into HTML.
base.TransformHtml(generator, element, gridContainer);
}
示例4: CreateNode
public static HtmlNode CreateNode(
HtmlDocument document,
string name,
string className = null,
HtmlNode parentNode = null)
{
var node = document.CreateElement(name);
if (!string.IsNullOrWhiteSpace(className))
{
node.SetAttributeValue("class", className);
}
if (parentNode != null)
{
parentNode.AppendChild(node);
}
return node;
}
示例5: TransformHtml
public override void TransformHtml(Generator generator, Drawable element, HtmlNode node)
{
var document = node.OwnerDocument;
var buttonContainer = document.CreateElement("a");
var style = element.Style;
// TODO: Move this to GeneratorBlock
if (style != null)
buttonContainer.Attributes.Add(document.CreateAttribute("class", style));
// Add our created element to the parent.
node.AppendChild(buttonContainer);
// For now we'll just add "Hello world" if a Button contains no content.
if (((Button)element).Text == null)
buttonContainer.AppendChild(document.CreateTextNode("Browse"));
// IMPORTANT: Unless you know better, always call this at the end. Otherwise the Content of this
// node will NOT be turned into HTML.
base.TransformHtml(generator, element, buttonContainer);
}
示例6: TransformHtml
public override void TransformHtml(Generator generator, Drawable element, HtmlNode node)
{
// TODO: Flesh this out. Rather bare bones at the moment.
var document = node.OwnerDocument;
var newElement = document.CreateElement("div");
var style = element.Style;
// TODO: Move this to GeneratorBlock, or not, at least not for this GeneratorBlock impl.
// Reason being is that I do some ContentProperty voodoo, which isnt appropriate for us here.
if (style != null)
newElement.Attributes.Add(document.CreateAttribute("class", style));
// Add our created element to the parent.
node.AppendChild(newElement);
// This is where special handling of Content comes in. I simply loop through the StackPanel and call generate.
// TODO: Try to generalize this and move it to GeneratorBlock. Will clean things up a bit.
foreach (var child in ((StackPanel)element).Children)
{
generator.Generate(newElement, child);
}
}
示例7: Parse
//.........这里部分代码省略.........
{
_oldstate = _state;
_state = ParseState.ServerSideCode;
continue;
}
}
}
break;
case ParseState.Comment:
if (_c == '>')
{
if (_fullcomment)
{
if ((Text[_index - 2] != '-') ||
(Text[_index - 3] != '-'))
{
continue;
}
}
if (!PushNodeEnd(_index, false))
{
// stop parsing
_index = Text.Length;
break;
}
_state = ParseState.Text;
PushNodeStart(HtmlNodeType.Text, _index);
continue;
}
break;
case ParseState.ServerSideCode:
if (_c == '%')
{
if (_index < Text.Length)
{
if (Text[_index] == '>')
{
switch (_oldstate)
{
case ParseState.AttributeAfterEquals:
_state = ParseState.AttributeValue;
break;
case ParseState.BetweenAttributes:
PushAttributeNameEnd(_index + 1);
_state = ParseState.BetweenAttributes;
break;
default:
_state = _oldstate;
break;
}
IncrementPosition();
}
}
}
break;
case ParseState.PcData:
// look for </tag + 1 char
// check buffer end
if ((_currentnode._namelength + 3) <= (Text.Length - (_index - 1)))
{
if (string.Compare(Text.Substring(_index - 1, _currentnode._namelength + 2),
"</" + _currentnode.Name, StringComparison.OrdinalIgnoreCase) == 0)
{
int c = Text[_index - 1 + 2 + _currentnode.Name.Length];
if ((c == '>') || (IsWhiteSpace(c)))
{
// add the script as a text node
HtmlNode script = CreateNode(HtmlNodeType.Text,
_currentnode._outerstartindex +
_currentnode._outerlength);
script._outerlength = _index - 1 - script._outerstartindex;
_currentnode.AppendChild(script);
PushNodeStart(HtmlNodeType.Element, _index - 1);
PushNodeNameStart(false, _index - 1 + 2);
_state = ParseState.Tag;
IncrementPosition();
}
}
}
break;
}
}
// finish the current work
if (_currentnode._namestartindex > 0)
{
PushNodeNameEnd(_index);
}
PushNodeEnd(_index, false);
// we don't need this anymore
Lastnodes.Clear();
}
示例8: GetStrippedForm
HtmlNode GetStrippedForm(HtmlNode OriginalForm, List<string> InputElementStrings)
{
OriginalForm.RemoveAllChildren();
foreach (string InputElementString in InputElementStrings)
{
HTML InputHtml = new HTML(InputElementString);
OriginalForm.AppendChild(InputHtml.Html.DocumentNode.FirstChild);
}
return OriginalForm;
}
示例9: GenerateHTML
/// <summary>
/// Traverse the directory structure present in provided DirectoryModel and
/// create HTML that will represent the directories and files that are found.
/// </summary>
/// <param name="directory">Directory containing subdirectories and articles.</param>
/// <param name="listFileDoc">Object representing HTML document.</param>
/// <param name="directoryDiv">Container representing div that will contain categories and articles.</param>
/// <param name="isSourceDir">Bool representing whether directoryDiv, is parent directory of article directory structure.</param>
static void GenerateHTML(DirectoryModel directory, HtmlDocument listFileDoc, HtmlNode directoryContainerDiv,
bool isSourceDir, ref int index, string categoriesUrlText)
{
// Hash directory path to be used as unique identifier for
// folder div's id attribute
index++;
string encryptedPath = EncryptStrings.EncryptToMD5String(directory.Path);
// Create div that will hold folder icon and directory name
HtmlNode directoryDiv = listFileDoc.CreateElement("div");
// Container for categories (subdirectories) and article links.
directoryDiv.SetAttributeValue("class", "directory");
directoryDiv.SetAttributeValue("id", encryptedPath);
// Check whether or not current directory, is the parent node
// of article directory structure (as this is first container to be seen)
string style = isSourceDir ? String.Format("z-index: {0};", index) : String.Format("z-index: -{0}; display: none", index);
directoryDiv.SetAttributeValue("style", style);
// div to hold category header and links to roll back to previous views
HtmlNode directoryCategoryContainer = listFileDoc.CreateElement("div");
directoryCategoryContainer.SetAttributeValue("id", "category-container");
// header for category section of directory div
HtmlNode directoryHeader = listFileDoc.CreateElement("h2");
directoryHeader.SetAttributeValue("class", "category-headers");
// add text node for header
HtmlNode categoryHeaderText = listFileDoc.CreateTextNode("Categories");
directoryHeader.AppendChild(categoryHeaderText);
directoryCategoryContainer.AppendChild(directoryHeader);
// create div to hold category urls used to roll back to a
//previous view
HtmlNode categoryUrlDiv = listFileDoc.CreateElement("div");
categoryUrlDiv.SetAttributeValue("class", "visited-categories-container");
// add category url text
HtmlNode categoryUrlText = listFileDoc.CreateTextNode(categoriesUrlText);
categoryUrlDiv.AppendChild(categoryUrlText);
directoryCategoryContainer.AppendChild(categoryUrlDiv);
// add container for category header and links for rolling back to particular views
// to the directory container div
directoryDiv.AppendChild(directoryCategoryContainer);
HtmlNode categoryRule = listFileDoc.CreateElement("hr");
categoryRule.SetAttributeValue("class", "header-rule");
directoryDiv.AppendChild(categoryRule);
// update current url string to be used by subordinate categories
string currentUrlName = Path.GetFileName(directory.Path);
if (categoriesUrlText == String.Empty)
{
categoriesUrlText += @"<a href='#' onclick='rollBack("""")'>Home</a>";
}
else
{
categoriesUrlText += @" > <a href='#' onclick='rollBack(""" + encryptedPath + @""")'>" +
currentUrlName + "</a>";
}
// Process subdirectories' contents and generate relevant
// html.
if (directory.Subdirectories.Count > 0)
{
foreach (DirectoryModel subdirectory in directory.Subdirectories)
{
isSourceDir = false;
HtmlNode subDirectoryDiv = listFileDoc.CreateElement("div");
subDirectoryDiv.SetAttributeValue("class", "subdirectory");
subDirectoryDiv.SetAttributeValue("name", EncryptStrings.EncryptToMD5String(subdirectory.Path));
subDirectoryDiv.SetAttributeValue("onclick", "bringToFront(this)");
HtmlNode folderParagraph = listFileDoc.CreateElement("p");
folderParagraph.SetAttributeValue("class", "folder-name");
HtmlTextNode text = listFileDoc.CreateTextNode(Path.GetFileName(subdirectory.Path));
folderParagraph.AppendChild(text);
subDirectoryDiv.AppendChild(folderParagraph);
directoryDiv.AppendChild(subDirectoryDiv);
GenerateHTML(subdirectory, listFileDoc, directoryContainerDiv, isSourceDir, ref index, categoriesUrlText);
}
}
// Container for links to show articles.
//.........这里部分代码省略.........
示例10: WriteLittleDocument
private void WriteLittleDocument(KeyValuePair<string, HtmlNode> contentNode, HtmlNode bodyNode)
{
bodyNode.AppendChild(contentNode.Value);
string htmlText = GetHtmlText();
var htmlBytes = Encoding.Default.GetBytes(htmlText);
using (var stream = File.Create(contentNode.Key + ".html"))
{
stream.Write(htmlBytes, 0, htmlBytes.Length);
}
contentNode.Value.Remove();
}
示例11: ReplaceAllChildren
/// <summary>
/// Replaces all child nodes with the supplied nodes and indents them +1 tab.
/// </summary>
private void ReplaceAllChildren(HtmlNode parent, IEnumerable<HtmlNode> nodes)
{
// Preserve the indentation of the parent.
var parentScope = CreateTextNode();
var prev = parent.PreviousSibling;
if (prev == null && parent.ParentNode != null)
prev = parent.ParentNode.PreviousSibling;
if (prev != null && prev.NodeType == HtmlNodeType.Text)
{
var m = TabsAndSpaces.Match(prev.InnerText);
if (m.Success)
parentScope.InnerHtml += m.Value;
}
// Add one tab of indentation for the children.
var childScope = CreateTextNode(parentScope.InnerText + "\t");
// Replace all children with supplied nodes (indented).
parent.RemoveAllChildren();
foreach (var option in nodes)
{
parent.AppendChild(childScope);
parent.AppendChild(option);
}
// Put the closing tag at the same indentation as the opening tag.
parent.AppendChild(parentScope);
}
示例12: PopulateIssueInfoNode
public void PopulateIssueInfoNode(HtmlNode issueInfoNode, HtmlNode kesiNode, HtmlNode mdNode)
{
string status = GetNodeInnerText(kesiNode, "./s:issueStatus", null);
if (status != null)
issueInfoNode.SetAttributeValue("status", status.EncodeXMLString());
string resolution = GetNodeInnerText(kesiNode, "./s:issueResolution", null);
if (resolution != null)
issueInfoNode.SetAttributeValue("resolution", resolution.EncodeXMLString());
string productName = GetNodeInnerText(kesiNode, "./s:issueProduct/s:productId", null);
if (productName != null && GetNodeInnerText(kesiNode, "./s:issueActivity/s:activityWhat", "Product") == "Product")
issueInfoNode.SetAttributeValue("productName", productName.EncodeXMLString());
string componentName = GetNodeInnerText(kesiNode, "./s:issueProduct/s:productComponentId", null);
if (componentName != null && GetNodeInnerText(kesiNode, "./s:issueActivity/s:activityWhat", "Component") == "Component")
issueInfoNode.SetAttributeValue("componentName", componentName.EncodeXMLString());
string priority = GetNodeInnerText(kesiNode, "./s:issuePriority", null);
if (priority != null)
issueInfoNode.SetAttributeValue("priority", priority.EncodeXMLString());
string severity = GetNodeInnerText(kesiNode, "./s:issueSeverity", null);
if (severity != null)
issueInfoNode.SetAttributeValue("severity", severity.EncodeXMLString());
string systemOS = GetNodeInnerText(kesiNode, "./s:issueComputerSystem/s:computerSystemOS", null);
if (systemOS != null)
issueInfoNode.SetAttributeValue("systemOS", systemOS.EncodeXMLString());
string systemPlatform = GetNodeInnerText(kesiNode, "./s:issueComputerSystem/s:computerSystemPlatform", null);
if (systemPlatform != null)
issueInfoNode.SetAttributeValue("systemPlatform", systemPlatform.EncodeXMLString());
string productVersion = GetNodeInnerText(kesiNode, "./s:issueProduct/s:productVersion", null);
if (productVersion != null)
issueInfoNode.SetAttributeValue("productVersion", productVersion.EncodeXMLString());
string assignedToName = GetIssueAssignedTo(kesiNode);
string assignedToUri = GetNodeInnerText(mdNode, "./o:issueAssignedToUri", null);
if (!string.IsNullOrEmpty(assignedToName)) {
HtmlNode assignedToNode = issueInfoNode.OwnerDocument.CreateElement("assignedTo");
issueInfoNode.AppendChild(assignedToNode);
assignedToNode.SetAttributeValue("name", assignedToName.EncodeXMLString());
if (!string.IsNullOrEmpty(assignedToUri))
assignedToNode.SetAttributeValue("uri", assignedToUri.EncodeXMLString());
}
string CCName = GetIssueCCPerson(kesiNode);
string CCUri = GetNodeInnerText(mdNode, "./o:issueCCPerson", null); // todo: change this to the right value
if (!string.IsNullOrEmpty(CCName)) {
HtmlNode assignedToNode = issueInfoNode.OwnerDocument.CreateElement("CC");
issueInfoNode.AppendChild(assignedToNode);
assignedToNode.SetAttributeValue("name", CCName.EncodeXMLString());
if (!string.IsNullOrEmpty(CCUri))
assignedToNode.SetAttributeValue("uri", CCUri.EncodeXMLString());
}
}
示例13: CopyInputElementsIntoForm
void CopyInputElementsIntoForm(HtmlNode SourceForm, HtmlNode DestinationForm)
{
foreach (HtmlNode Node in SourceForm.ChildNodes)
{
if (Node.Name.Equals("input"))
{
DestinationForm.AppendChild(CopyNodeTopElement(Node, DestinationForm.OwnerDocument));
}
else if (Node.ChildNodes.Count > 0)
{
CopyInputElementsIntoForm(Node, DestinationForm);
}
}
}
示例14: AddReferences
void AddReferences(HtmlNode node, string elementTitle, HashSet<string> references)
{
if (node == null)
return;
HtmlNode referencesNode = node.OwnerDocument.CreateElement(elementTitle);
foreach (string reference in references)
referencesNode.AppendChild(CreateNodeWithTextContent(node.OwnerDocument, "s1:referenceUri", reference));
node.AppendChild(referencesNode);
}
示例15: AddAnnotatedText
void AddAnnotatedText(HtmlNode node, string elementTitle, string annotatedData, bool putInCDataBlock = true)
{
if (node == null)
return;
XmlDocument doc = (XmlDocument)node.OwnerDocument;
HtmlNode annotatedNode;
if (putInCDataBlock)
annotatedNode = doc.CreateCDataElementInsideWrapperNode(elementTitle, annotatedData);
else
annotatedNode = CreateNodeWithTextContent(doc, elementTitle, annotatedData.EncodeXMLString());
//annotatedNode.Name = elementTitle;
node.AppendChild(annotatedNode);
}