I was trying to read in many HTML documents but I don't want to declare
"HTMLDocumentCl ass m_doc" as a local variable, since I need to use its
properties in other functions as well.
So I declare it as a class variable and the problem occurs:
the content of m_doc never changes when I read in different HTML
documents. It always contains the information of the very first HTML
document. It seems "i_html_doc.wri te(o_page_text) ;" can not overwrite
the infomation into m_doc once it's not empty.
// class variable
HTMLDocumentCla ss m_doc = new HTMLDocumentCla ss();
public IHTMLElement ReadInHTML(stri ng file_path)
{
using (StreamReader sr = new StreamReader(fi le_path))
{
object[] o_page_text = { sr.ReadToEnd() };
IHTMLDocument2 i_html_doc = m_doc as IHTMLDocument2;
try
{
i_html_doc.writ e(o_page_text);
IHTMLElement body = i_html_doc.body ;
return body;
}
catch (Exception ex)
{
Console.Write(e x.Message + "\n\n" + ex.StackTrace);
return null;
}
}
}
I tried "m_doc.clea r()" each time when I read in a new HTML document,
but it seems it does not help.
Anyone can help me out? Thank you very much!
--
erxuan
"HTMLDocumentCl ass m_doc" as a local variable, since I need to use its
properties in other functions as well.
So I declare it as a class variable and the problem occurs:
the content of m_doc never changes when I read in different HTML
documents. It always contains the information of the very first HTML
document. It seems "i_html_doc.wri te(o_page_text) ;" can not overwrite
the infomation into m_doc once it's not empty.
// class variable
HTMLDocumentCla ss m_doc = new HTMLDocumentCla ss();
public IHTMLElement ReadInHTML(stri ng file_path)
{
using (StreamReader sr = new StreamReader(fi le_path))
{
object[] o_page_text = { sr.ReadToEnd() };
IHTMLDocument2 i_html_doc = m_doc as IHTMLDocument2;
try
{
i_html_doc.writ e(o_page_text);
IHTMLElement body = i_html_doc.body ;
return body;
}
catch (Exception ex)
{
Console.Write(e x.Message + "\n\n" + ex.StackTrace);
return null;
}
}
}
I tried "m_doc.clea r()" each time when I read in a new HTML document,
but it seems it does not help.
Anyone can help me out? Thank you very much!
--
erxuan