我使用C#并需要解析HTML以将属性读取到键值对中。 例如给出下面的HTML代码段
如何解析HTML节点的属性
<DIV myAttribute style="BORDER-BOTTOM: medium none; BACKGROUND-COLOR: transparent; BORDER-TOP: medium none" id=my_ID anotherAttribNamedDIV class="someclass">
请注意,属性可以是
1.键= “value” 对例如class="someclass"
2.键值对例如id=my_ID
(无引号值)
3.普通属性,例如myAttribute
,它不具有“价值”
我需要将它们存储到与键值对的字典如下
key=myAttribute value=""
key=style value="BORDER-BOTTOM: medium none; BACKGROUND-COLOR: transparent; BORDER-TOP: medium none"
key=id value="my_ID"
key=anotherAttribNamedDIV value=""
key=class value="someclass"
我找正则表达式来做到这一点。
无法解析[X] HTML与正则表达式做到这一点。 http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – Homam 2011-04-11 14:50:31
不要为你的html标签使用大写字母。 – David 2011-04-11 17:26:19