Solved

vb.net application parse through html file and find values

Posted on 2009-05-04
2
301 Views
Last Modified: 2013-11-08
ok, I have a vb.net forms application, this application has to read values from an html file on the hard drive.

What I want to do is write a function that can pull all the values I need from the html file into my program, here is an example of two of the values I need to pull out.

The good thing is that each value is embedded in a span tag and has it's own unique id attribute.

I need someone to guide me through parsing the dom to get the element values by id.

Here is two examples:

How would I write my code to pull the values Blue, and Busy from my html file.

<span id="lblColor">Blue</span>
<span id="lblStatus">Busy</span>

thanks in advance.
0
Comment
Question by:talker2004
  • 2
2 Comments
 
LVL 27

Accepted Solution

by:
nmarun earned 500 total points
ID: 24297921
Here's the code for the html file reader. Just tweak to check if the .Name property is 'span' and in the attributes section, check for 'lblColor' and 'lblStatus' attributes.

listBox1.Items.Clear()
Dim i As Integer = 0
Dim xtr As New XmlTextReader("c:\test.html")
xtr.WhitespaceHandling = WhitespaceHandling.None
 
While xtr.Read()
    Dim s As String = (((i.ToString() & "-") + xtr.NodeType & " ") + xtr.Name & " ") + xtr.Value.ToString() & " "
    
    If xtr.HasAttributes Then
        For j As Integer = 0 To xtr.AttributeCount - 1
            xtr.MoveToAttribute(j)
            s += (" ATT:" & xtr.Name & " =") + xtr.GetAttribute(j)
        Next
    End If
    listBox1.Items.Add(s)
    i += 1
End While

Open in new window

0
 
LVL 27

Expert Comment

by:nmarun
ID: 24297933
The above code adds formatted values to a listbox, you might want to remove that piece of code.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question