troubleshooting Question

Parsing an HTML file, Part II - for Rajesh75

Avatar of k3n51mm
k3n51mm asked on
Visual Basic.NET
22 Comments1 Solution655 ViewsLast Modified:
Thanks for your previous help. I'm close but for now I'm not getting the desired output. Of course the real solution is a little more involved than the example we discussed, but I think I have the concepts down. I have to find the correct table in the document before I can grab the data, so here's what I came up with. However, all I'm getting is a carriage return for each table. If you can find anything wrong, it would help a lot. Code follows.

'---------------------------------BEGIN CODE---------------------------

                '.......from your code (worked perfectly)......
                hDoc = iHtml
                'acquire collection of table tags from document
                Dim collTable As IHTMLElementCollection = hDoc.getElementsByTagName("TABLE")
                'declare variable for each <table> element in document
                Dim elmTable As IHTMLElement
                For Each elmTable In collTable
                    If elmTable.getAttribute("summary") = "DWLayoutTable" Then
                        'acquire collection of rows from table
                        Dim collTblChld As IHTMLElementCollection = elmTable.children
                        'declare variable for each <tr> element in table
                        Dim elmTblChld As IHTMLElement
                        'declare variable for each <td>'s contents
                        Dim szValue As String = ""
                        'step through each row of data in HTML table
                        For Each elmTblChld In collTblChld
                            If elmTblChld.tagName = "TR" Then
                                'declare variable for <td> child elements
                                Dim elmChld As mshtml.IHTMLElement
                                'acquire collection of table data cells from row
                                Dim collChld As mshtml.IHTMLElementCollection = elmTblChld.children
                                'get each cell's values
                                For Each elmChld In collChld
                                    'abstract table data for conversion to flat pipe-delimited text
                                    szValue = elmChld.innerText
                                    'remove whitespace
                                    szValue = szValue.Trim
                                    'concatenate row data
                                    szOutputLine = szOutputLine & szValue & "|"
                                Next elmChld
                            End If
                            'append line of row data to output stringBuilder
                            objStrBld.Append(szOutputLine & ControlChars.CrLf)
                        Next elmTblChld
                    End If
                Next elmTable

                '.... to output code
                Dim wtrTxtFile As StreamWriter....

'----------------------------------END CODE----------------------------
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 22 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 22 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros