Results 1 to 6 of 6

Thread: HTML Document.

  1. #1

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    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


  2. #2
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: HTML Document.

    try this?

    vb Code:
    1. mc_OutputWebBrowser.Document.Body.InnerHtml = "<b>This is a test</b>"

    Kris

  3. #3

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: HTML Document.

    whats that "mc_OutputWebBrowser"? its an object of webbrowser control or something else.

    vb Code:
    1. Dim WebOC As New WebBrowser
    2.  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


  4. #4
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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

  5. #5

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    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


  6. #6
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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
  •  



Click Here to Expand Forum to Full Width