Solved

IHTMLElement and IHTMLElementCollection

Posted on 2002-05-02
11
4,385 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how do i create updater to My Activex application? 3 108
Prevent this page from creating additional dialogs. 3 790
Window placement 17 100
zeroFront challenge 7 136
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

739 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