【发布时间】:2012-07-04 01:41:08
【问题描述】:
我正在尝试使用 HAP 库在 HTML 标记中创建一个新属性:
HtmlDocument doc = new HtmlDocument();
doc.Load(PATH);
HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//input");
nodes[0].Attributes["foo"].Value = "baa"; /* try add 'foo' attribute with 'baa' value in input HTML element. */
doc.Save(@"C:\foo.html");
但它会得到一个异常:
Object reference not set to an instance of an object.
如何解决这个问题?
【问题讨论】:
-
您检查过
nodes是否为非空吗?
标签: c# html-agility-pack html