EDN Admin
Well-known member
hi,all, I need to retrieve a vector of html tag names from an attribute value (a piece of html code) of a xml dom node; this is what i tried:
<div style="color:Black;background-color:White; <pre>
vector<wstring> ProcTagStrVec;
MSHTML::IHTMLDocument2Ptr htmDoc1 = NULL;
SAFEARRAY *psaStrings1 = SafeArrayCreateVector(VT_VARIANT, 0, 1);
CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER, IID_IHTMLDocument2, (<span style="color:Blue; void**) &htmDoc1);
VARIANT *param1 = NULL;
HRESULT hr = SafeArrayAccessData(psaStrings1, (LPVOID*)¶m1);
param1->vt = VT_BSTR;
param1->bstrVal = SysAllocString(varSrc1.bstrVal);
hr = SafeArrayUnaccessData(psaStrings1);
hr = htmDoc1->write(psaStrings1);
MSHTML::IHTMLElementPtr pElemBody1 = NULL;
MSHTML::IHTMLDOMNodePtr pHTMLBodyDOMNode1 =NULL;
hr = htmDoc1->get_body(&pElemBody1);
<span style="color:Blue; if(SUCCEEDED(hr))
{
hr = pElemBody1->QueryInterface(IID_IHTMLDOMNode,(<span style="color:Blue; void**)&pHTMLBodyDOMNode1);
<span style="color:Blue; if(SUCCEEDED(hr))
{
ProcessDomNodeSmartWrapper(pHTMLBodyDOMNode1, ProcTagStrVec);
}
}
[/code]
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; void CXMLDOMFromVCDlg:rocessDomNodeSmartWrapper(MSHTML::IHTMLDOMNodePtr pNode, vector<wstring> &ProcTagStrVec)
{
<span style="color:Blue; if(pNode->nodeType == 1)
{
<span style="color:Blue; if(lstrcmpW(pNode->nodeName, L<span style="color:#A31515; "HTML") != 0 && lstrcmpW(pNode->nodeName, L<span style="color:#A31515; "BODY") != 0 && lstrcmpW(pNode->nodeName, L<span style="color:#A31515; "HEAD") != 0)
{
ProcTagStrVec.push_back(wstring(pNode->nodeName));
MSHTML::IHTMLDOMChildrenCollectionPtr pChElemColl = MSHTML::IHTMLDOMChildrenCollectionPtr(pNode->childNodes);
<span style="color:Blue; long lLength = pChElemColl->length;
<span style="color:Blue; for(<span style="color:Blue; int i = 0; i < lLength; i++)
{
ProcessDomNodeSmartWrapper(MSHTML::IHTMLDOMNodePtr(pChElemColl->item(i)), ProcTagStrVec);
}
}<span style="color:Blue; else{
MSHTML::IHTMLDOMChildrenCollectionPtr pChElemColl = MSHTML::IHTMLDOMChildrenCollectionPtr(pNode->childNodes);
<span style="color:Blue; long lLength = pChElemColl->length;
<span style="color:Blue; for(<span style="color:Blue; int i = 0; i < lLength; i++)
{
ProcessDomNodeSmartWrapper(MSHTML::IHTMLDOMNodePtr(pChElemColl->item(i)), ProcTagStrVec);
}
}
}<span style="color:Blue; else <span style="color:Blue; if(pNode->nodeType == 3){
VARIANT varNodeVal;
HRESULT hr;
hr = pNode->get_nodeValue(&varNodeVal);
<span style="color:Green; // MessageBox(varNodeVal.bstrVal, _T("The content of this text node is"), MB_OK);
<span style="color:Blue; if(hr == S_OK)
{
ProcTagStrVec.push_back(L<span style="color:#A31515; "T");
}
}
}
[/code]
<br/>
suppose I have a html source like:
<div style="color:Black;background-color:White; <pre>
<TD vAlign=top><FONT size=1 face=<span style="color:#A31515; "ms sans serif,arial,geneva">Mac Tools </FONT></TD>
[/code]
<br/>
the above program should give me a vector contains:
<pre><TD><FONT>T[/code]
but it only gave me:
<pre><FONT>T</TD>[/code]
this is really weird, so whats going on?
cheers
daiyue
View the full article
<div style="color:Black;background-color:White; <pre>
vector<wstring> ProcTagStrVec;
MSHTML::IHTMLDocument2Ptr htmDoc1 = NULL;
SAFEARRAY *psaStrings1 = SafeArrayCreateVector(VT_VARIANT, 0, 1);
CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER, IID_IHTMLDocument2, (<span style="color:Blue; void**) &htmDoc1);
VARIANT *param1 = NULL;
HRESULT hr = SafeArrayAccessData(psaStrings1, (LPVOID*)¶m1);
param1->vt = VT_BSTR;
param1->bstrVal = SysAllocString(varSrc1.bstrVal);
hr = SafeArrayUnaccessData(psaStrings1);
hr = htmDoc1->write(psaStrings1);
MSHTML::IHTMLElementPtr pElemBody1 = NULL;
MSHTML::IHTMLDOMNodePtr pHTMLBodyDOMNode1 =NULL;
hr = htmDoc1->get_body(&pElemBody1);
<span style="color:Blue; if(SUCCEEDED(hr))
{
hr = pElemBody1->QueryInterface(IID_IHTMLDOMNode,(<span style="color:Blue; void**)&pHTMLBodyDOMNode1);
<span style="color:Blue; if(SUCCEEDED(hr))
{
ProcessDomNodeSmartWrapper(pHTMLBodyDOMNode1, ProcTagStrVec);
}
}
[/code]
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; void CXMLDOMFromVCDlg:rocessDomNodeSmartWrapper(MSHTML::IHTMLDOMNodePtr pNode, vector<wstring> &ProcTagStrVec)
{
<span style="color:Blue; if(pNode->nodeType == 1)
{
<span style="color:Blue; if(lstrcmpW(pNode->nodeName, L<span style="color:#A31515; "HTML") != 0 && lstrcmpW(pNode->nodeName, L<span style="color:#A31515; "BODY") != 0 && lstrcmpW(pNode->nodeName, L<span style="color:#A31515; "HEAD") != 0)
{
ProcTagStrVec.push_back(wstring(pNode->nodeName));
MSHTML::IHTMLDOMChildrenCollectionPtr pChElemColl = MSHTML::IHTMLDOMChildrenCollectionPtr(pNode->childNodes);
<span style="color:Blue; long lLength = pChElemColl->length;
<span style="color:Blue; for(<span style="color:Blue; int i = 0; i < lLength; i++)
{
ProcessDomNodeSmartWrapper(MSHTML::IHTMLDOMNodePtr(pChElemColl->item(i)), ProcTagStrVec);
}
}<span style="color:Blue; else{
MSHTML::IHTMLDOMChildrenCollectionPtr pChElemColl = MSHTML::IHTMLDOMChildrenCollectionPtr(pNode->childNodes);
<span style="color:Blue; long lLength = pChElemColl->length;
<span style="color:Blue; for(<span style="color:Blue; int i = 0; i < lLength; i++)
{
ProcessDomNodeSmartWrapper(MSHTML::IHTMLDOMNodePtr(pChElemColl->item(i)), ProcTagStrVec);
}
}
}<span style="color:Blue; else <span style="color:Blue; if(pNode->nodeType == 3){
VARIANT varNodeVal;
HRESULT hr;
hr = pNode->get_nodeValue(&varNodeVal);
<span style="color:Green; // MessageBox(varNodeVal.bstrVal, _T("The content of this text node is"), MB_OK);
<span style="color:Blue; if(hr == S_OK)
{
ProcTagStrVec.push_back(L<span style="color:#A31515; "T");
}
}
}
[/code]
<br/>
suppose I have a html source like:
<div style="color:Black;background-color:White; <pre>
<TD vAlign=top><FONT size=1 face=<span style="color:#A31515; "ms sans serif,arial,geneva">Mac Tools </FONT></TD>
[/code]
<br/>
the above program should give me a vector contains:
<pre><TD><FONT>T[/code]
but it only gave me:
<pre><FONT>T</TD>[/code]
this is really weird, so whats going on?
cheers
daiyue
View the full article