|
-
Aug 27th, 2010, 12:29 AM
#1
Thread Starter
Fanatic Member
HTML Document.
Hi,
I need to Read a HTML File and retrieve Tag value and attribute value.
In HTMLDocument there is no LOAD function to load a html file,but there are methods like getElementByTagName.
How to load a html file in htmldocument class?
Visual Studio.net 2010
If this post is useful, rate it

-
Aug 27th, 2010, 12:55 AM
#2
Re: HTML Document.
try this?
vb Code:
mc_OutputWebBrowser.Document.Body.InnerHtml = "<b>This is a test</b>"
Kris
-
Aug 27th, 2010, 01:08 AM
#3
Thread Starter
Fanatic Member
Re: HTML Document.
whats that "mc_OutputWebBrowser"? its an object of webbrowser control or something else.
vb Code:
Dim WebOC As New WebBrowser
WebOC.Document.Body.InnerHtml = "<b>This is a test</b>"
i tried like this but am getting "Object reference ..." exception.
Visual Studio.net 2010
If this post is useful, rate it

-
Aug 27th, 2010, 01:27 AM
#4
Re: HTML Document.
If you want to parse html file, I would suggest two methods.
1.Parse the HTML file using regular expressions
2. Load the HTML in a webbrowser and use the document.getelementbyid method
3. Or try this parser. (not I have never tried)
Please mark you thread resolved using the Thread Tools as shown
-
Aug 27th, 2010, 02:06 AM
#5
Thread Starter
Fanatic Member
Re: HTML Document.
"2. Load the HTML in a webbrowser and use the document.getelementbyid method"
How to load the HTML File in webrowser?
i don't need a control in forms.. i just want to get the values inside tags.
Visual Studio.net 2010
If this post is useful, rate it

-
Aug 27th, 2010, 03:01 AM
#6
Re: HTML Document.
Hope this helps
Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim browser As New WebBrowser
AddHandler browser.DocumentCompleted, AddressOf browser_LoadCompleted
browser.Visible = False
'Add the Html
browser.DocumentText = "<html><body>Please enter your name:<br/>" & _
"<input type='text' name='userName' id='userName' value='testUsername'/><br/>" & _
"<a href='http://www.microsoft.com'>continue</a>" & _
"</body></html>"
WebBrowser1.DocumentText = "<html><body>Please enter your name:<br/>" & _
"<input type='text' name='userName' id='userName' value='testUsername'/><br/>" & _
"<a href='http://www.microsoft.com'>continue</a>" & _
"</body></html>"
End Sub
'Fires when the document is loaded completely in browser
Private Sub browser_LoadCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
'Read the entire document
Dim document As System.Windows.Forms.HtmlDocument = _
sender.Document
If document IsNot Nothing And document.All("userName") IsNot Nothing Then
'Access the control Here
Dim UserName As HtmlElement = document.All("userName")
'Read the value
Dim userNameValue As String = UserName.GetAttribute("value")
End If
End Sub
Last edited by danasegarane; Aug 27th, 2010 at 03:27 AM.
Reason: Read the html value code updated
Please mark you thread resolved using the Thread Tools as shown
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|