473,473 Members | 1,513 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

IHTMLELement2

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


Nov 21 '05 #1
4 2159
Curtis,

See this sample ad the end

http://www.windowsformsdatagridhelp....f-56dbb63fdf1c

I hope this helps,

Cor

"Curtis" <cs*****@hotmail.com> schreef in bericht
news:%2****************@TK2MSFTNGP14.phx.gbl...
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


Nov 21 '05 #2
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

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Oo**************@TK2MSFTNGP12.phx.gbl...
Curtis,

See this sample ad the end

http://www.windowsformsdatagridhelp....f-56dbb63fdf1c

I hope this helps,

Cor

"Curtis" <cs*****@hotmail.com> schreef in bericht
news:%2****************@TK2MSFTNGP14.phx.gbl...
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

Nov 21 '05 #3
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
Nov 21 '05 #4
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

"Curtis" <cs*****@hotmail.com> schreef in bericht
news:%2****************@TK2MSFTNGP10.phx.gbl...
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

Nov 21 '05 #5

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

Similar topics

2
by: gregl | last post by:
Anyone know how to obtain the true size of the html document's body? The control contains the size that the control was set to. The body object appears to contain the same size. That information...
0
by: Vinod. | last post by:
Hi all, I have added browser control to a windows form. I am loading pages having multiple frames. I have noticed that the focus in a text is not maintained when the application is deactivated....
2
by: mparisi | last post by:
I hope that there is someone who can help me. I have written a process to entirely automate a sequence of web pages. It works great and I spent a ton of time on it since I am a novice C#...
0
by: Andla Rand | last post by:
Hi, I have an uggly solution to send information to a file upload control or IHTMLInputFileElement. For security reason Microsoft doesn't allow this. To get around this I created this small...
5
by: Dave A | last post by:
I am writing an ASP.NET tool that will allow the client to create their own online froms. ie the client can add tect boxes, text, drop downs,etc with absolutely no technical skill what so ever....
5
by: Curtis | last post by:
Why are there 4 options to choose from and which one is the correct one to use? IHTMLElement or IHTMLElement2 or IHTMLElement3 or IHTMLElement4 Thanks, Curtis
0
by: Ben | last post by:
Hi all, I am trying to write a little app that will generate a thumbnail image of a website. Having searched the web I have found various bits of code that appear to do the job and have written...
7
by: dwandless | last post by:
I have successfully installed a BHO in IE7. Using C#. Now I'm trying to figure out how to trap various events. onkeypress, oncut, oncontextmenu, etc. I have tried calling in various...
0
by: k1ngdrew | last post by:
I am trying to use mshtml to parse a web page without using IE. I create the HTMLDocument object, and then assign to it the output value from createDocumentFromUrl(). I know that this is at least...
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
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
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...
0
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
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...
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.