473,395 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Help: How can I enumerate span element attributes using MSHTML

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.

Sep 16 '08 #1
2 6556
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?
Sep 17 '08 #2
On Sep 17, 9:21*am, cloftis <celof...@gmail.comwrote:
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?- Hide quoted text -

- Show quoted text -
Ok, I finally licked this. Instead of using the MSHTML.dll, I used XML
objects instread. Here's what I ended up with:

Dim xDoc As New Xml.XmlDocument
xDoc.LoadXml("<span attr1='somevalue'
attr2='somevalue' attrN='...'>markup</span>")
If xDoc.ChildNodes(0).Attributes.Count 0 Then
For Each xAttribute As Xml.XmlAttribute In
xDoc.ChildNodes(0).Attributes
Debug.WriteLine(xAttribute.Name & ":" &
xAttribute.Value)
Next
End If

Maybe this will be able to help someone else.

Tags: MSHTML, XML, Element attributes, span attributes, DOM Element
attributes
Sep 17 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: mike | last post by:
Hello, After trying to validate this page for a couple of days now I was wondering if someone might be able to help me out. Below is a list of snippets where I am having the errors. 1. Line 334,...
8
by: slim | last post by:
hi again all, i am still working on the website as mentioned in earlier threads and have hit another snag... http://awash.demon.co.uk/index.php http://awash.demon.co.uk/vd.css the php is...
4
by: blueey | last post by:
I have a span element somewhere somewhere in between my table. How do i loop through the elemenst (namely in this case radio and text) and retreive the values of the child elements and it's type....
27
by: Nicholas Couch | last post by:
I have a little form with a couple of dynamically generated list boxes. When the user makes a selection from the first box, the second box is refreshed. When they make a selection from the second...
4
by: Joseph | last post by:
The idea is to show only one of the <Baby_Div> while hiding all the others. At the moment all I have managed to do is to show each <Baby_Div> in turn as expected, but the problem is that once a...
9
by: developer | last post by:
Does anyone know what is the way IE treats span tags(<span>) and table tags(<tr>, <td>)? Should the <span> tag be encolsed in tds and trs if it placed with other elements that are in a table? Can...
26
by: johkar | last post by:
I need to cancel the link and execute a function onclick of all the links within the span tag which has a class of "container" assigned. There will be only one span tag with this class applied. ...
7
by: mavigozler | last post by:
IE7 does not appear to set an event on contained text inside SPAN elements whose 'onclick', 'onmouseover', and 'onmouseout' events, defying the HTML recommendation. Firefox appears to conform. ...
0
by: hzgt9b | last post by:
Using VB.NET under .NET 1.1 in VS2003, BACKGROUND I have a windows application that dereferences the MsHTM.dll. The app is successfully able to parse existing HTM documents allowing me to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.