How to Load string into mshtml object?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • adwooley2

    #1

    How to Load string into mshtml object?

    Can't seem to find anything that works for me. I have a small bit of
    HTML that is stored in a string variable. I want to assign this string
    to an mshtml object (IHTMLDocument2 I believe), so that I can traverse
    the elements and attributes cleanly.
    Does anybody know of a way to load this string into an mshtml object?
    I would be beholdin'

    Tks,
    adwooley2

  • Oenone

    #2
    Re: How to Load string into mshtml object?

    Does anybody know of a way to load this string into an mshtml object?

    Are you using .NET 2003 or 2005?

    --

    (O)enone


    Comment

    • adwooley2

      #3
      Re: How to Load string into mshtml object?

      Using .NET 2005.



      Oenone wrote:
      Does anybody know of a way to load this string into an mshtml object?
      >
      Are you using .NET 2003 or 2005?
      >
      --
      >
      (O)enone

      Comment

      • Oenone

        #4
        Re: How to Load string into mshtml object?

        adwooley2 wrote:
        Using .NET 2005.
        I've done this using the new VS2005 WebBrowser control. It seemed to be a
        little more complex than I was expecting, but still do-able.

        Unfortunately the control didn't seem to like being instantiated from
        scratch in code, so I had to create a form and place a WebBrowser control on
        it. I don't know why this was necessary but it was the only way I could get
        it to work. With this done (I've called my form WebBrowserForm, and the
        WebBrowser control placed upon it is named WebBrowser), the following code
        should do what you want:

        \\\
        Public Function HtmlDoc(ByVal HTML As String) As Windows.Forms.H tmlDocument

        'Create an instance of the form containing the WebBrowser control
        dim browserForm as New WebBrowserForm

        'Set the document text to be our HTML
        browserForm.Web Browser.Documen tText = HTML

        'Wait until the document is loaded
        Do Until browserForm.Web Browser.ReadySt ate = _
        WebBrowserReady State.Loaded _
        Or browserForm.Web Browser.ReadySt ate = _
        WebBrowserReady State.Complete
        Application.DoE vents()
        Loop

        'Return the document
        Return browserForm.Web Browser.Documen t

        End Function
        ///

        You can then interrogate the DOM using the returned HtmlDocument object.

        HTH,

        --

        (O)enone


        Comment

        • adwooley2

          #5
          Re: How to Load string into mshtml object?

          Oenone,
          Much appreciated.
          Yes, I think that this is what I was looking for. And thanks for the
          code - that makes it clearer.

          Rgds,
          adwooley2


          Oenone wrote:
          adwooley2 wrote:
          Using .NET 2005.
          >
          I've done this using the new VS2005 WebBrowser control. It seemed to be a
          little more complex than I was expecting, but still do-able.
          >
          Unfortunately the control didn't seem to like being instantiated from
          scratch in code, so I had to create a form and place a WebBrowser control on
          it. I don't know why this was necessary but it was the only way I could get
          it to work. With this done (I've called my form WebBrowserForm, and the
          WebBrowser control placed upon it is named WebBrowser), the following code
          should do what you want:
          >
          \\\
          Public Function HtmlDoc(ByVal HTML As String) As Windows.Forms.H tmlDocument
          >
          'Create an instance of the form containing the WebBrowser control
          dim browserForm as New WebBrowserForm
          >
          'Set the document text to be our HTML
          browserForm.Web Browser.Documen tText = HTML
          >
          'Wait until the document is loaded
          Do Until browserForm.Web Browser.ReadySt ate = _
          WebBrowserReady State.Loaded _
          Or browserForm.Web Browser.ReadySt ate = _
          WebBrowserReady State.Complete
          Application.DoE vents()
          Loop
          >
          'Return the document
          Return browserForm.Web Browser.Documen t
          >
          End Function
          ///
          >
          You can then interrogate the DOM using the returned HtmlDocument object.
          >
          HTH,
          >
          --
          >
          (O)enone

          Comment

          Working...