简体   繁体   English

如何构建自定义 AngleSharp 元素并将 HTML 部分插入/转换到元素中

[英]How to build a custom AngleSharp element and insert/transform HTML sections into the element

I am using AngleSharp and would like to know how to transform sections of HTML to something like SVG, XML or another custom bracket supported format.我正在使用 AngleSharp 并想知道如何将 HTML 部分转换为 SVG、XML 或其他自定义括号支持的格式。

Question: how do I build a custom AngleSharp IElement and then transform the div (or link) contents inside the custom element ie take the div/links I found, and then put the div content inside in the custom element问题:如何构建自定义 AngleSharp IElement,然后转换自定义元素内的 div(或链接)内容,即获取我找到的 div/链接,然后将 div 内容放入自定义元素中


Below is the code I am trying下面是我正在尝试的代码

var divToTransform = document.QuerySelector("div.class1.class2");
// need a custom transform, something simple like replacing the tags
new IElement myCustomeAngleBracketQml = new CustomeAngleBracketQml(divToTransform);
//something simple like replacing the tags
myCustomeAngleBracketQml.Replace("div", Tag).With("QmlDiv");
//insert the content
myCustomeAngleBracketQml.TextContent = divToTransform.innerContent();
//1) how to put this back in the place of the original div, after deleting that div?
///2) *how to target a specific node in the Dom
document./*after Div with class, or Div with Id*/.AppendChild(element);

thanks谢谢

use Xml Linq XElement使用 Xml Linq XElement

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            XElement doc = new XElement("QmlDiv", new object[] {
                new XElement("class1", new object[] {
                    new XElement("class2",divToTransform.innerContent)
                }),
            });
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM