Solved

IHTMLElement and IHTMLElementCollection

Posted on 2002-05-02
11
4,453 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
Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

 
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

617 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