// JP opened flex table

Click to See Complete Forum and Search --> : can any one help me to get inner text from HTMLDocument


Wolvorine
February 21st, 2007, 06:01 AM
i just want to get inner text from the html file , for it i just read any html file on my disc and then to filter the text from those file i made below code...but just as my expectation it doesnt work...can anyone help me to solve this problem?



strHtmlData = " ......................";// suppose this is html text with tags etc which needs to be filter
IWebBrowser2* pWebBrowser = NULL;
CoInitialize(NULL);

HRESULT hr ;

hr = CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_ALL ,REGCLS_SINGLEUSE , (LPVOID*)&pWebBrowser);

if(hr==S_OK)
{

IDispatch* pHtmlDocDispatch = NULL;
IHTMLDocument2 * pHtmlDoc = NULL;

hr = pWebBrowser->get_Document (&pHtmlDocDispatch);

if (SUCCEEDED (hr) && (pHtmlDocDispatch != NULL))
{
hr = pHtmlDocDispatch->QueryInterface (IID_IHTMLDocument2,
(void**)&pHtmlDoc);
if (SUCCEEDED (hr) && (pHtmlDoc != NULL))
{
CComPtr<IHTMLElement> pHTMLElement;

HRESULT hr=pHtmlDoc->get_body(&pHTMLElement);

BSTR bstrHtml,bstrText;
bstrHtml = (BSTR) strHtmlData .c_str();
pHTMLElement->put_innerHTML(bstrHtml); //this is my html text
pHTMLElement->get_innerText(bstrText); //here is what i was looking for

SysFreeString(bstrHtml);
SysFreeString(bstrText);
pHTMLElement=NULL;


pHtmlDoc->Release();
}

pHtmlDocDispatch->Release();
}

pWebBrowser->Release ();
}

Krishnaa
February 21st, 2007, 06:07 AM
Whats the problem ? Whats not working ?

Wolvorine
February 21st, 2007, 06:17 AM
i am working in console exe mode but when i reach to hr = CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_ALL ,REGCLS_SINGLEUSE , (LPVOID*)&pWebBrowser);


then it never goes down to fulfill other statements, seems like it became hanged or in Wait....

Krishnaa
February 21st, 2007, 07:26 AM
Is your code using this interface in multithreaded env by any chance ?

Wolvorine
February 21st, 2007, 07:47 AM
no its not, i just want to create this object in non multi threaded executable...this function will be executed once and then close.

//JP added flex table