c#读取html文件节点,C# 通过 HtmlDocument 操作HTML节点

本文介绍了如何在C#中使用HtmlDocument类来操作HTML节点,包括修改网页元素属性,创建表格,以及处理WebBrowser控件的导航事件。示例代码展示了如何设置HTML节点的属性,以及在用户导航前进行验证。
摘要由CSDN通过智能技术生成

C# 通过 HtmlDocument 操作HTML节点时,会发生不停地刷新的情况,在对html文档操作后加以判断即可解决这种问题。

Public Sub setMainUlr(ByVal WebBrowser1 As WebBrowser)

Dim pElem As HtmlElement = Nothing

'即时信息页面

pElem = WebBrowser1.Document.All("myFrame")

If Not pElem Is Nothing Then

If pElem.GetAttribute("src") <> myFrameUrl Then

Dim ax As AccessXml = New AccessXml()

pElem.SetAttribute("src", myFrameUrl)

End If

End If

'展示图片页面

pElem = WebBrowser1.Document.All("slice")

If Not pElem Is Nothing Then

If pElem.GetAttribute("src") <> pictureUrl Then

Dim ax As AccessXml = New AccessXml()

pElem.SetAttribute("src", pictureUrl)

End If

End If

End Sub

通用方法:

private void DisplayCustomersTable()

{

DataSet customersSet = new DataSet();

DataTable customersTable = null;

SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Customers", "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;");

sda.Fill(customersTable);

customersTable = customersSet.Tables[0];

if (webBrowser1.Document != null)

{

HtmlElement tableRow = null;

HtmlElement headerElem = null;

HtmlDocument doc = webBrowser1.Document;

HtmlElement tableElem = doc.CreateElement("TABLE");

doc.Body.AppendChild(tableElem);

HtmlElement tableHeader = doc.CreateElement("THEAD");

tableElem.AppendChild(tableHeader);

tableRow

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值