473,890 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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='somevalu e'
attr2='somevalu e' attrN='...'>mar kup</span>"
3 Dim objSpan As HTMLSpanElement =
browser.Documen t.createElement ("span")
4 objSpan.innerHT ML = 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.attribu tes 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 6608
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='somevalu e'
attr2='somevalu e' attrN='...'>mar kup</span>"
3 * * Dim objSpan As HTMLSpanElement =
browser.Documen t.createElement ("span")
4 * * objSpan.innerHT ML = 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.attribu tes 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.Documen t.createElement ("span")
iElement.innerH TML = "<span attr1='somevalu e'
attr2='somevalu e' attrN='...'>mar kup</span>"
Dim iNode As IHTMLDOMNode = CType(iElement, IHTMLDOMNode)
Dim iAttrColl As IHTMLAttributeC ollection =
CType(iNode.att ributes, IHTMLAttributeC ollection)
Try
For Each attr As IHTMLDOMAttribu te2 In iAttrColl
If CType(attr, IHTMLDOMAttribu te).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='somevalu e'
attr2='somevalu e' attrN='...'>mar kup</span>"
3 * * Dim objSpan As HTMLSpanElement =
browser.Documen t.createElement ("span")
4 * * objSpan.innerHT ML = 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.attribu tes 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.Documen t.createElement ("span")
* * * * * * iElement.innerH TML = "<span attr1='somevalu e'
attr2='somevalu e' attrN='...'>mar kup</span>"
* * * * * * Dim iNode As IHTMLDOMNode = CType(iElement, IHTMLDOMNode)
* * * * * * Dim iAttrColl As IHTMLAttributeC ollection =
CType(iNode.att ributes, IHTMLAttributeC ollection)
* * * * * * Try
* * * * * * * * For Each attr As IHTMLDOMAttribu te2 In iAttrColl
* * * * * * * * * * If CType(attr, IHTMLDOMAttribu te)..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='somevalu e'
attr2='somevalu e' attrN='...'>mar kup</span>")
If xDoc.ChildNodes (0).Attributes. Count 0 Then
For Each xAttribute As Xml.XmlAttribut e In
xDoc.ChildNodes (0).Attributes
Debug.WriteLine (xAttribute.Nam e & ":" &
xAttribute.Valu e)
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
6338
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, column 13: there is no attribute "SRC" <bgsound src="C:\My Documents\zingwent.mids"> You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is...
8
5169
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 pulling a name and placing it under the thumbnail (the text is
4
5607
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. Also how do i check that the element that has been clicked is the span element?I cant seem to use the type attribute as it gives me error. it seems simple enough doesnt it?
27
4769
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 box, I concatenate the selections from the two boxes and add the string to a list at the top of the form, using createElement and appendChild. The list is actually a bunch of span elements contained within a div. Each span element includes a small...
4
1488
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 <Baby_Div>.innerHTML is replaced by one of the procedures, it does not work anymore, ie, the <Baby_Div> content is not displayed anymore, once code replaces the actual 'Blah' string. Structure: <Top-Div> <Child_Div (6 in total)> <Baby_Span>
9
7223
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 the span tag itself contain table tags within it? I have some scripting code and when I wrap the span in table elements it does not find the html within the span. Here is an example.... <tr><td colspan="4" align="left"><span...
26
8137
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. I know you can get a specific tag using document.getElementsByTagName('span'), but I am unsure how to get the one with the class="container". I know there is a getAttribute method, just need a pointer or two to put it all together. Once I know...
7
2348
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. Is that so?
0
985
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 access the DOM objects as needed. With my latest changes I want to utilize the MsHTM.dll to parse some text for me. For instance, I'd like to be able to parse the following
0
9975
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9812
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10799
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10899
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10446
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7154
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5832
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4655
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.