如何以编程方式加载HTML文档以添加到文档的< head&gt ;? [英] How to programmatically load a HTML document in order to add to the document's <head>?

查看:130
本文介绍了如何以编程方式加载HTML文档以添加到文档的< head&gt ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们提供了来自客户端的HTML'wrapper'文件,我们需要将内容插入,然后呈现HTML。



在我们渲染插入了我们的内容的HTML,我需要添加一些标签到客户端包装的< head> 部分,比如脚本文件,css和一些meta的引用标签。



所以我在做的是

$ pre code> string html = File.ReadAllText(wrapperLocation,Encoding.GetEncoding(iso-8859-1));

现在我拥有完整的HTML。然后,我在该字符串中搜索预定义的内容,并将其内容插入到该字符串中,然后进行呈现。



如何创建HTML文档的实例并根据需要修改< head> 部分?



编辑:我不想引用 System.Windows.Forms so WebBrowser不是一个选项。

解决方案

我无法得到一个自动化的解决方案,

  public void void PopulateCssTag(string tags)
{
// tags是一个预先压缩的字符串包含我需要的所有标签。
this.Wrapper = this.Wrapper.Replace(< / head>,tags +< / head>);
}


We are supplied with HTML 'wrapper' files from the client, which we need to insert out content into, and then render the HTML.

Before we render the HTML with our content inserted, I need to add a few tags to the <head> section of the client's wrapper, such as references to our script files, css and some meta tags.

So what I'm doing is

string html = File.ReadAllText(wrapperLocation, Encoding.GetEncoding("iso-8859-1"));

and now I have the complete HTML. I then search for a pre-defined content well in that string and insert our content into that, and render it.

How can I create an instance of a HTML document and modify the <head> section as required?

edit: I don't want to reference System.Windows.Forms so WebBrowser is not an option.

解决方案

I couldn't get an automated solution to this, so it came down to a hack:

public virtual void PopulateCssTag(string tags)
{
    // tags is a pre-compsed string containing all the tags I need.
    this.Wrapper = this.Wrapper.Replace("</head>", tags + "</head>");
}

这篇关于如何以编程方式加载HTML文档以添加到文档的&lt; head&gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆