Solved

vb.net application parse through html file and find values

Posted on 2009-05-04
2
299 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
Comment Utility
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
Comment Utility
The above code adds formatted values to a listbox, you might want to remove that piece of code.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
c# code 19 56
Why, and when, to use Windows Workflow 1 16
Handle null when using linq in this line 1 20
fomat Json objects 6 15
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now