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.StartPosit ion = FormStartPositi on.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.EventHan dler( ButtonClick );
this.Controls.A dd( 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 ).createDocumen tFromUrl(
"file:///" + System.Environm ent.CurrentDire ctory + "\\myDoc.ht ml", "null" );
IHTMLElementCol lection elemColl = (IHTMLElementCo llection)
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 UCOMIPersistFil e and Load function... same results.
Byez, -Mat-
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.StartPosit ion = FormStartPositi on.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.EventHan dler( ButtonClick );
this.Controls.A dd( 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 ).createDocumen tFromUrl(
"file:///" + System.Environm ent.CurrentDire ctory + "\\myDoc.ht ml", "null" );
IHTMLElementCol lection elemColl = (IHTMLElementCo llection)
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 UCOMIPersistFil e and Load function... same results.
Byez, -Mat-
Comment