本版本为dhtml.net 1.1版,如有疑问请发邮件给我(sqzhuyi@gmail.com)
本版本较1.0版更新如下:
1、解决了一些基本BUG
2、为Element添加了GetElementsByTagName,GetElementsByName,GetElementsClass方法
3、添加document和element的搜索功能,支持类似jquery搜索
示例:
string html = @"<p id=p1><span>aaa</span>
<b>bbb</b><textarea><i>af</i></textarea>
<b class='b1'>b1b1b1</b><input type=checkbox /></p>";
Document doc = new Document(html);
ElementCollect els = doc.Search("#p1 b[class=b1]");
Document 成员如下:
属性
public ElementCollect Elements | 获取HTML文档中的所有节点 |
public Element Body | 获取body节点 |
public string Title | 获取文档title字符串 |
public FormCollect Forms | 获取文档中所有form节点 |
public FrameCollect Frames | 获取文档中所有frame节点 |
public ScriptCollect Scripts | 获取文档中所有script元素 |
public ImageCollect Images | 获取文档中所有img元素 |
方法
public ElementCollect GetElementsByTagName(string tag) | 通过tagName获取节点集合 |
public ElementCollect GetElementsByName(string name) | 通过节点name属性获取节点集合 |
public ElementCollect GetElementsByClass(string clas) | 通过节点class属性获取节点集合 |
public Element GetElementById(string id) | 通过节点id获取该节点 |
public ElementCollect Search(string path) | 搜索文档中符合条件的节点,表达式示例:#div1 span a[class="over"] |
Element 成员如下:
属性
public int Index | 当前节点在elements集合中的索引 |
public string Id | 节点ID |
public string Name | 节点name |
public string Class | 节点class |
public string Style | 节点style |
public string TagName | 节点tagName |
public AttributeCollect Attributes | 节点属性集合 |
public string InnerHTML | 节点innerHTML |
public string OuterHTML | 节点outerHTML |
public Element PreviousSibling | 当前节点的上一个兄弟节点 |
public Element NextSibling | 当前节点的下一个兄弟节点 |
public Element PreviousElement | 当前节点所在集合中的上一个节点 |
public Element NextElement | 当前节点所在集合中的下一个节点 |
public Element ParentElement | 当前节点的父节点 |
public ElementCollect ChildElements | 当前节点的子节点集合 |
方法
public ElementCollect GetElementsByTagName(string tag) | 通过tagName获取节点集合 |
public ElementCollect GetElementsByName(string name) | 通过节点name属性获取节点集合 |
public ElementCollect GetElementsByClass(string clas) | 通过节点class属性获取节点集合 |
public ElementCollect Search(string path) | 搜索文档中符合条件的节点,表达式示例:#div1 span a[class="over"] |
源码下载:
http://download.csdn.net/source/2645389
作者:朱会震