Simple but difficult to find solution for loading HTML into object

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

Hi, I have a simple thing I need to do but just doesn't work in VB.NET.


I have a string with HTML code and I want to load it into a HTMLDocument
object or something similiar to it so I can access the the tags and tags
value (<td> <table>, etc) by code.

But it just doesn't work in VB.NET but works in VB6. Please someone just
show me the right way to do this simple thing.

My code (which doesnt work):

Dim str0 as string = "<html> <body> Hi</body></html>
Dim doc as HTMLDocument = new HTMLDocument

doc.body.innerHTML = str0
''' This doesn't work. How can I load HTML into an HTML like
object??? Please help and thanks in advance




J.
 
So long as the HTML is 'well formed' you will be able to load it into an
XmlDocument object which provides all the functionality you will need for
finding and interrogating elements.

Unfortunately, a number of web browsers (IE included) will quite happily
render HTML that is not 'well formed' and this allows HTML writers to be a
bit lazy in this respect.

If you are writing the HTML yourself then you can ensure that it is 'well
formed'.
 
Joe said:
Hi, I have a simple thing I need to do but just doesn't work in VB.NET.


I have a string with HTML code and I want to load it into a HTMLDocument
object or something similiar to it so I can access the the tags and tags
value (<td> <table>, etc) by code.

But it just doesn't work in VB.NET but works in VB6. Please someone just
show me the right way to do this simple thing.

My code (which doesnt work):

Dim str0 as string = "<html> <body> Hi</body></html>
Dim doc as HTMLDocument = new HTMLDocument

doc.body.innerHTML = str0
''' This doesn't work. How can I load HTML into an HTML like
object??? Please help and thanks in advance




J.

I'm not sure how VB.NET renders the DOM, but if it does it like it's
supposed to, I might know why your program isn't working.

Try removing the <html><body> tags from the string and pushing that into
the HTMLDocument object's body.innerHTML

With the way the DOM works, it will yell at you if you try and put
<html></html> inside of the body.innerHTML (which is in actuallity
<html><body>[here]</body></html>.

As I said, I'm not sure how VB.NET impliments the HTML DOM, so I could
be wrong, but good luck none the less!
 
Joe,

You can by instance have alook at the answers given by Herfried and me in
this newsgroup on your same question yesterday.

Cor
 
Back
Top