且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将HTML合并到现有的asp.net页中

更新时间:2023-02-18 13:35:03

如果页面是整页,我假设您只想提取正文内容.可能最简单的方法是解析<body> </body>标记之间的内容.


OP希望获得有关如何完成此操作的信息.好的,一种方法是使用XML从HTML中选择主体节点(假设它在格式正确的XML文档中),然后选择InnerText.然后,您可以将该内容写到文字控件中.

可以这样读取:
If the page is a full page, I assume you want to just extract the body content. Probably the simplest way to do this would be to just parse the content out between the <body> </body> tags.


The OP wanted information on how to accomplish this. Well, one way would be to use XML to select the body node from the HTML (assuming it''s in a well formed XML document), and select the InnerText. You could then write this content out into a literal control.

This could be read in like:
XmlDocument document = new XmlDocument();
document.Load(...); // This is where you'd load the XHTML in.
var node = document.DocumentElement.SelectSingleNode("/html/body");
string text = node.InnerText;

// Now, populate the ASP.NET literal control.
litContent.Text = text;

[/Edit]


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CodeProjectWeb.WebForm1"

    ValidateRequest="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <% Response.Write(s);%>
    </form>
</body>
</html>







public partial class WebForm1 : System.Web.UI.Page
    {
        protected string s;
        protected void Page_Load(object sender, EventArgs e)
        {
            s = "<input value=\"some value\">";
        }
        protected void btnClick_Click(object sender, EventArgs e)
        {
        }
    }
}




祝你好运;




Good luck;


谢谢大家的帮助,它已经解决了!
Thanks guys for the help, its resolved!