Solved

IHTMLElement and IHTMLElementCollection

Posted on 2002-05-02
11
4,230 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
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now