IHTMLELement2

C

Curtis

Does anyone know how I can use the .getElementsByTagName to only receive
parent tags. I am only concerned with the outside TD tags and I need to
capture information from a TD tag that is at a specific position but the
table within a table throws off the count of my TD tags. For example how to
I get all of the TD tags in the following table except the ones that are
within the inner table.
<table width="100%" border = "1" cellspacing="1" cellpadding="0" border="0"
class="MainTable">
<tr class="tableoncell">
<td>Sample Data</td>

<td align="center">
<table border="1" cellpadding="1" cellspacing="1">
<tr>
<td>Embedded Child Table</td>
<td>Test Data</td>
</tr>

</table>
</td>

<td>
Table Text
</td>
<td>
1
</td>
</tr>
</table>

I see that IHTMLElement2 has a property that called canHaveChildren but it
seems to be read only. Any suggestions or help would be greatly
appreciated.

Thanks,

Curtis
 
C

Curtis

Cor,

Thanks for the reply but that example doesn't really answer my question. I
need a way to delete out the child tags in my example table. I cannot find a
way to efficiently do that within the mshtml class. Does anyone know if this
is possible. Is there a way in the MSHTML class to only get the first level
of TD tags for instance in collection of elements? Is their a property I can
set when performing the .getElementsbyTagName method to only get the first
level of TD tags.

Thanks,
Curtis
 
C

Curtis

Cor,

I ended up using code such as this:
CODE:

Dim myDoc As IHTMLDocument2 = New HTMLDocument
Dim elmBody As IHTMLElement
Dim elmBody2 As IHTMLElement2
Dim elmTD As IHTMLElement
Dim elmChild As IHTMLElement
Dim elmTR As IHTMLElement
Dim elmTable As IHTMLElement
Dim elmTBODY As IHTMLElement
Dim colTR As IHTMLElementCollection
Dim colChild As IHTMLElementCollection
Dim colTD As IHTMLElementCollection
Dim colTable As IHTMLElementCollection
Dim colTBODY As IHTMLElementCollection
Dim sHTML As Object = txtInput.Text
Dim I As Integer
Dim Z As Integer
Dim X As Integer
Dim Y As Integer
Dim S As Integer
Dim strTable As String
Dim intPos As String
Dim ChildHash As New Hashtable
myDoc.write(sHTML)
elmBody = myDoc.body()
colTable = elmBody.children
For Y = 0 To colTable.length - 1
elmTable = colTable.item(Y)
If elmTable.tagName = "TABLE" Then
colTBODY = elmTable.children
For I = 0 To colTBODY.length - 1
elmTBODY = colTBODY.item(I)
If elmTBODY.tagName = "TBODY" Then
colTR = elmTBODY.children
For S = 0 To colTR.length - 1
elmTR = colTR.item(S)
colTD = elmTR.children
For Z = 0 To colTD.length - 1
elmTD = colTD.item(Z)
MsgBox(elmTD.innerHTML)
intPos = InStr(elmTD.innerHTML, "<TABLE")
If intPos > 0 Then
MsgBox("table within a table :" &
elmTD.innerText)
'Processing
End If
Next
Next
End If
Next
End If
Next
End Sub

INPUT:

<html>
<body>
<table width="100%" border = "1" cellspacing="1" cellpadding="0" border="0"
class="MainTable">
<tr class="tableoncell">
<td>Sample Data</td>
<td align="center">
<table border="1" cellpadding="1" cellspacing="1">
<tr>
<td>Qty</td>
<td>1</td>

</tr>

</table>
</td>
<td>
Table Text
</td>
<td>
1
</td>
</tr>
</table>
</body>
</html>

It got a bit more complicated than I wanted to but the .children method
accesses the html document in a tree like strucuture which is what I want.
If you have any suggestions for improving my code please let me know. Thanks
for your help.

Thanks,
Curtis
 
C

Cor Ligthert [MVP]

Curtis,

I would probably have gone in your case for a method like I showed. Placed a
switch when I had found the parent that I needed and than at the next <td>
tag do my actions.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top