MSHTML...

  • Thread starter Thread starter Mat
  • Start date Start date
M

Mat

Hi all.
I need to build a little HTML parser. I made 2 versions, for console e for
window.
In console mode it seems to work (but not always, sometimes it doesn't parse
the HTML file), in window mode (target winexe) I get no result...
This is my code:

=== CODE ===
using MSHTML;
using System;
using System.Drawing;
using System.Windows.Forms;

public class HTMLParser : Form
{
[STAThread] public static int Main( string[] args )
{
Application.Run( new HTMLParser() );
return 0;
}

public HTMLParser()
{
this.Text = "HTML Parser";
this.StartPosition = FormStartPosition.Manual;
this.Location = new Point( 100, 100 );
this.Size = new Size( 200, 200 );

Button button = new Button();
button.Text = "Parse";
button.Location = new Point( 10, 80 );
button.Size = new Size( 80, 25 );

button.Click += new System.EventHandler( ButtonClick );
this.Controls.Add( button );
}

private void ButtonClick( object sender, EventArgs evArgs )
{
try
{
HTMLDocument document = new HTMLDocument();
IHTMLDocument2 iDocument2;

( (IHTMLDocument2)document ).write( "<html></html>" );
( (IHTMLDocument2)document ).close();

iDocument2 = ( (IHTMLDocument4)document ).createDocumentFromUrl(
"file:///" + System.Environment.CurrentDirectory + "\\myDoc.html", "null" );

IHTMLElementCollection elemColl = (IHTMLElementCollection)
iDocument2.all;
foreach( IHTMLElement elem in elemColl )
MessageBox.Show( elem.tagName );
}
catch( Exception e )
{
MessageBox.Show( e.ToString() );
}
}
}
======

Someone can hel me?
I tried also to use UCOMIPersistFile and Load function... same results.

Byez, -Mat-
 
Mat,

Does it work when you debug it, and not work when you don't debug it? I
have a feeling that because you are not waiting for the parsing to complete
it might be bombing. Try placing a try/catch block around your code in the
event handler for the button click, and see if an exception is thrown.

Hope this helps.
 
Does it work when you debug it, and not work when you don't debug it?
I
have a feeling that because you are not waiting for the parsing to complete
it might be bombing. Try placing a try/catch block around your code in the
event handler for the button click, and see if an exception is thrown.

I don't use Visual Studio .NET so I can't use the Visual Debugger.
I don't know how does the cordbg work...

Uhm... the code of my event handler is inside a try/catch block
Another thing, if an exception is thrown the program execution is usually
interrupted...
 
Back
Top