Jeff Johnson
2009-09-01 17:54:09 UTC
Has anyone else had trouble getting attributes from HtmlElement objects
contained in the HtmlDocument object (what you get with the Document
property)? I loaded some (valid) HTML via the DocumentText property and when
I do something like
webBrowser1.Document.Body.Children[1].GetAttribute("class")
(where this child element happens to be a DIV tag and definitely has a class
attribute) I get an empty string. However, if I use the DomElement property
of this HtmlElement and cast it to mshtml.HTMLDivElement, I can then
(through some nasty casting and retrieving of enumerators), finally dig down
and get the value of this attribute. Anyone else experienced something like
this?
(And why in the world didn't MS put an Attributes collection on the
HtmlElement class to begin with??)
Before you ask: Yes, the document has fully loaded by the time I run the
code above.
contained in the HtmlDocument object (what you get with the Document
property)? I loaded some (valid) HTML via the DocumentText property and when
I do something like
webBrowser1.Document.Body.Children[1].GetAttribute("class")
(where this child element happens to be a DIV tag and definitely has a class
attribute) I get an empty string. However, if I use the DomElement property
of this HtmlElement and cast it to mshtml.HTMLDivElement, I can then
(through some nasty casting and retrieving of enumerators), finally dig down
and get the value of this attribute. Anyone else experienced something like
this?
(And why in the world didn't MS put an Attributes collection on the
HtmlElement class to begin with??)
Before you ask: Yes, the document has fully loaded by the time I run the
code above.