How to loop through IHTMLAttributeCollection

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

By using foreach statement of C#, we can loop through
IHTMLAttributeCollection as follows:

IHTMLAttributeCollection myAttrColl =
(IHTMLAttributeCollection) myNode. attributes;
IHTMLDOMAttribute myAttr;

foreach myAttr in myAttrColl
{
if (myAttr.specified) //do something
}

How can we accomplish the same by using the 'for' loop? I
am asking this since I need to write the same code for
both C# and J#. But in J#, there is no foreach loop. Using
for loop, I tried the following:

for (int i=0; i < MyAttrColl.get_length(); i++)
{
myAttr = (IHTMLDOMAttribute) oAttrColl.item(i);
//now do something
}

But the syntax for item method is IHTMLDOMAttribute.item
(ref Object name). Hence, I get an error saying: method
IHTMLDOMAttribute.item(int i) not found.

Please help?

Thanks,
Bob
 
All the IHTML...Collection implent the IEnumerator interface,
that mean that you can use while loop to do it:

IHTMLDOMAttribute myAttr
IEnumerator ie=myAttColl.GetEnumerator()
while (e.MoveNext())
{
myAttr=(IHTMLDOMAttribute)e.Current;
....
}
 
Back
Top