当前位置:   article > 正文

html 怎么获取属性,获取html标签属性

html元素 如何获取他的标签类型

为了获取html代码一些标签属性,我们可以把这些html当作为一段xml的字符串来处理。可以参考下图:ec542d85f7759d8a7b065feb67442cd4.png

上图相关代码:

View Code

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Xml;

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

string htmlcode = "

MvpPhoto.jpg%5C%22";

XmlNodeList xnl = GetNoteList(htmlcode, "//img");

for (int i = 0; i < xnl.Count; i++)

{

Response.Write(xnl[i].Attributes["alt"].Value + "

");

Response.Write(xnl[i].Attributes["src"].Value + "

");

Response.Write(xnl[i].Attributes["width"].Value + "

");

Response.Write(xnl[i].Attributes["height"].Value + "

");

}

}

private XmlNodeList GetNoteList(string xmlText, string tag)

{

XmlDocument xDoc = new XmlDocument();

xDoc.Load(new System.IO.MemoryStream(System.Text.Encoding.GetEncoding("UTF-8").GetBytes(xmlText)));

return xDoc.SelectNodes(tag);

}

}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/110654?site
推荐阅读
相关标签
  

闽ICP备14008679号