Solved

IHTMLElement and IHTMLElementCollection

Posted on 2002-05-02
11
4,297 Views
Last Modified: 2013-11-20
I have a site with a HTML code's looking as "<OBJECT ...>
<EMBED>...</EMBED></OBJECT>". I can't :( to get a tag <EMBED> throught interfaces IHTMLElement and IHTMLElementCollection. Why? Perhaps, is there another way?

This part of the my code:
HRESULT CConvertor::TagFlashProcess(CComVariant & tagObject, BSTR bBase,
                                             IHTMLElement *  pElement)
{
     USES_CONVERSION;

// m_pDoc is pointer to the IWebBrowser2
     if (m_pDoc == NULL) return E_FAIL;

     CComPtr <IHTMLElementCollection> pColl = NULL;
     CComPtr <IHTMLElementCollection> pElCol = NULL;
     CComPtr <IHTMLElementCollection> pParamCol = NULL;
     CComPtr <IDispatch>                     pDisp = NULL;
     CComPtr <IHTMLElement>                pEl = NULL;
     CComPtr <IHTMLElement>                pElPar = NULL;

     if (pElement == NULL) m_pDoc ->get_all(&pColl);
          else
          {
               pElement ->get_all(&pDisp);
               if (pDisp == NULL) return E_FAIL;

               pDisp.QueryInterface(&pColl);
               pDisp.Release();
          }

     if (pColl == NULL) return E_FAIL;

     pColl ->tags (tagObject, &pDisp);

     if (pDisp == NULL) return E_FAIL;

     pDisp.QueryInterface (&pElCol);
     pDisp.Release();
     if (pElCol == NULL) return E_FAIL;

     long len = 0;

     pElCol->get_length(&len);

     if (len == 0) return S_OK;

        for ( long i = 0; i < len; i++ )
     {
          CComVariant     varName;
          CComVariant varIndex;

          pDisp.Release();
          pEl.Release();

          varIndex = (long) i;
          pElCol->item(varIndex, varName, &pDisp);
          if (pDisp == NULL) return E_FAIL;
          if ( FAILED(pDisp.QueryInterface(&pEl)) || (pEl == NULL) )
               break;
          pDisp.Release();

                pEl ->... and etc.
}

Sorry for my english, he is not so well.
Best regards,
Vadik
0
Comment
Question by:vadik
  • 3
  • 3
  • 2
  • +1
11 Comments
 
LVL 3

Expert Comment

by:danny_pav
ID: 6986138
Call embed a stylee in the header of the html and then the parser will find it.
0
 
LVL 1

Author Comment

by:vadik
ID: 6986172
Can you explain it?
0
 
LVL 3

Expert Comment

by:danny_pav
ID: 6986216
<HEAD>
<STYLE>
   EMBED { }
</STYLE>
</HEAD>

now the parser will find it.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 12

Expert Comment

by:migel
ID: 6989075
Hi!
may be IHTMLDocument2::get_embeds Method will help you?
you get IHTMLElementCollection object by this method and work with <EMBED> objects like any IHTMLElement ones.
Good luck!
0
 
LVL 1

Author Comment

by:vadik
ID: 6990297
I checked IHTMLDocument::get_embeds at first. It doesn't work for this circumstance too.

And i can't change <HEAD> and <STYLE> just because the IHTMLElment::innerHTML property is read-only for both of them.
0
 
LVL 12

Expert Comment

by:migel
ID: 6990923
Hi!
can you point to full HTML page with this tags. Just for testing and debuging?
0
 
LVL 1

Author Comment

by:vadik
ID: 6990979
0
 
LVL 12

Accepted Solution

by:
migel earned 500 total points
ID: 6993288
Hello
I tested some code and found that MSHTML have defect (???) IHTMLElement for <OBJECT> reports that it have no childs but they exist!
I think that you have to manually parse inner HTML for <OBJECT> tag
for example:

          CComPtr<IHTMLElement> pDocElem;
          CComPtr<IHTMLElementCollection> pElemCollections;
          pHTMLDoc2->get_all(&pElemCollections);

          COleVariant varName;
          varName = SysAllocString(L"OBJECT");
          CComPtr<IDispatch> spDispEmbed;
          pElemCollections->tags(varName, &spDispEmbed);
          {
          CComPtr<IHTMLElementCollection> spCollectEmbed;
          spDispEmbed->QueryInterface(IID_IHTMLElementCollection, (void**)&spCollectEmbed);
          if (spCollectEmbed)
               {
               spCollectEmbed->get_length(&lLen);
               for (int i = 0; i < lLen; i++)
                    {
                    CComPtr<IDispatch> pItem;
                    COleVariant vt = (long)i;
                    spCollectEmbed->item(vt, vt, &pItem);
                    CComPtr<IHTMLElement> spElement;
                    pItem->QueryInterface(IID_IHTMLElement, (void**)&spElement);
// spElement->get_all returns empty collection!
                    BSTR bsHTML;
                    spElement->get_innerHTML(&bsHTML);
                    // parse for <embed>
                    SysFreeString(bsHTML);
                    }
               }
          }
0
 
LVL 1

Expert Comment

by:luvjd
ID: 9918731
Hi Vadik..
Try this easy way..

MSHTML::IHTMLDocument2Ptr pDoc(GetHtmlDocument());      
MSHTML::IHTMLDocument3Ptr pDoc3 = pDoc;      
MSHTML::IHTMLElementCollectionPtr pCollection ,pCollection1;      
MSHTML::IHTMLElementPtr pEle,pEle2;
pCollection = pDoc3->getElementsByTagName(_T("OBJECT"));
            
if(pCollection)
{
    pEle = pCollection->item(CComVariant(0),CComVariant(0));
}

Luv..
Jd
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 84
Shell script to login to remote m/c and execute commands 10 78
Fibonacci challenge 11 121
"Black Box" Testing of Control System Software 2 50
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question