Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

IHTMLElement and IHTMLElementCollection

Posted on 2002-05-02
11
Medium Priority
?
4,534 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

715 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