On Sep 16, 5:07*pm, cloftis <celof...@gmail.comwrote:
Using VS2003, VB and MSHTML,
Using an HTMLSpanElement I want to enumerate the attributes of a SPAN
tag.
1 * * 'For testing sake
2 * * Dim strMarkup as String = "<span attr1='somevalue'
attr2='somevalue' attrN='...'>markup</span>"
3 * * Dim objSpan As HTMLSpanElement =
browser.Document.createElement("span")
4 * * objSpan.innerHTML = strMarkup
After the above code runs, I want to loop throught all the attributes
and inspect their names and values but I haven't found an easy way to
accomplish this... *any suggestions?
I've tried using objSpan.attributes but it always has a large number
of elements in the array regardless of the number of elements I put in
strMarkup.
Your thoughts appreciated.
Some progress... here's the code that I came up with to enumerate an
element's attributes:
Dim iElement As IHTMLElement =
browser.Document.createElement("span")
iElement.innerHTML = "<span attr1='somevalue'
attr2='somevalue' attrN='...'>markup</span>"
Dim iNode As IHTMLDOMNode = CType(iElement, IHTMLDOMNode)
Dim iAttrColl As IHTMLAttributeCollection =
CType(iNode.attributes, IHTMLAttributeCollection)
Try
For Each attr As IHTMLDOMAttribute2 In iAttrColl
If CType(attr, IHTMLDOMAttribute).specified Then
Debug.WriteLine(attr.name & ":" & attr.value)
End If
Next
Catch ex As Exception
Debug.WriteLine(ex.ToString)
End Try
The problem I am still having is that the innerHTML that I specify
does not appear to get parsed so when I loop throught the list of
attributes my custom attributes are not found...
How can I get enumerate the attributes specificed in the innerHTML of
the span tag above?