Skip to content Skip to sidebar Skip to footer

Mshtml: Createdocumentfromstring Instead Of Createdocumentfromurl

I'd like to use the MSHTML library to parse some HTML that I have in a string variable. However, I can't figure out how to do this. I can easily parse the contents of a webpage g

Solution 1:

You can;

Dim odoc AsObjectSet odoc = CreateObject("htmlfile") '// late binding'// or:'// Set odoc = New HTMLDocument '// for early binding

odoc.open
odoc.write "<p> In his house at R'lyeh, dead <b>Cthulhu</b> waits dreaming</p>"
odoc.Close
MsgBox odoc.body.outerHTML

Solution 2:

For straight HTML code such as Access-Rich-Text this does it:

Dim HTMLDoc AsNew HTMLDocument

HTMLDoc.Body.innerHTML = strHTMLText

Solution 3:

This is a much better example. You will not get a null exception, nor late binding.

(And if you use WPF, just add System.Windows.Forms in your reference.)

Dim a AsObject
        a = New mshtml.HTMLDocument

        a.open()
        a.writeln(code)
        a.close()

        DoUntil a.readyState = "complete"
            System.Windows.Forms.Application.DoEvents()
        LoopDim doc As mshtml.HTMLDocument = a



        Dim b As mshtml.HTMLSelectElement = doc.getElementsByTagName("Select").item("lang", 0)

Post a Comment for "Mshtml: Createdocumentfromstring Instead Of Createdocumentfromurl"