IHTMLELement2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Curtis

    #1

    IHTMLELement2

    Does anyone know how I can use the .getElementsByT agName 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="MainTabl e">
    <tr class="tableonc ell">
    <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






  • Cor Ligthert [MVP]

    #2
    Re: IHTMLELement2

    Curtis,

    See this sample ad the end



    I hope this helps,

    Cor

    "Curtis" <csch_nu@hotmai l.com> schreef in bericht
    news:%23YS1HxGu FHA.3452@TK2MSF TNGP14.phx.gbl. ..[color=blue]
    > Does anyone know how I can use the .getElementsByT agName 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="MainTabl e">
    > <tr class="tableonc ell">
    > <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
    >
    >
    >
    >
    >
    >[/color]


    Comment

    • Curtis

      #3
      Re: IHTMLELement2

      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 .getElementsbyT agName method to only get the first
      level of TD tags.

      Thanks,
      Curtis

      "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
      news:OohpfHHuFH A.1264@TK2MSFTN GP12.phx.gbl...[color=blue]
      > Curtis,
      >
      > See this sample ad the end
      >
      > http://www.windowsformsdatagridhelp....f-56dbb63fdf1c
      >
      > I hope this helps,
      >
      > Cor
      >
      > "Curtis" <csch_nu@hotmai l.com> schreef in bericht
      > news:%23YS1HxGu FHA.3452@TK2MSF TNGP14.phx.gbl. ..[color=green]
      >> Does anyone know how I can use the .getElementsByT agName 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="MainTabl e">
      >> <tr class="tableonc ell">
      >> <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[/color][/color]


      Comment

      • Curtis

        #4
        Re: IHTMLELement2

        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 IHTMLElementCol lection
        Dim colChild As IHTMLElementCol lection
        Dim colTD As IHTMLElementCol lection
        Dim colTable As IHTMLElementCol lection
        Dim colTBODY As IHTMLElementCol lection
        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(sHT ML)
        elmBody = myDoc.body()
        colTable = elmBody.childre n
        For Y = 0 To colTable.length - 1
        elmTable = colTable.item(Y )
        If elmTable.tagNam e = "TABLE" Then
        colTBODY = elmTable.childr en
        For I = 0 To colTBODY.length - 1
        elmTBODY = colTBODY.item(I )
        If elmTBODY.tagNam e = "TBODY" Then
        colTR = elmTBODY.childr en
        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.in nerHTML)
        intPos = InStr(elmTD.inn erHTML, "<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="MainTabl e">
        <tr class="tableonc ell">
        <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


        Comment

        • Cor Ligthert [MVP]

          #5
          Re: IHTMLELement2

          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" <csch_nu@hotmai l.com> schreef in bericht
          news:%23SMU6WKu FHA.3252@TK2MSF TNGP10.phx.gbl. ..[color=blue]
          > 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 IHTMLElementCol lection
          > Dim colChild As IHTMLElementCol lection
          > Dim colTD As IHTMLElementCol lection
          > Dim colTable As IHTMLElementCol lection
          > Dim colTBODY As IHTMLElementCol lection
          > 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(sHT ML)
          > elmBody = myDoc.body()
          > colTable = elmBody.childre n
          > For Y = 0 To colTable.length - 1
          > elmTable = colTable.item(Y )
          > If elmTable.tagNam e = "TABLE" Then
          > colTBODY = elmTable.childr en
          > For I = 0 To colTBODY.length - 1
          > elmTBODY = colTBODY.item(I )
          > If elmTBODY.tagNam e = "TBODY" Then
          > colTR = elmTBODY.childr en
          > 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.in nerHTML)
          > intPos = InStr(elmTD.inn erHTML, "<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="MainTabl e">
          > <tr class="tableonc ell">
          > <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
          >[/color]


          Comment

          Working...