CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Location
    Germany
    Posts
    418

    IHTMLSelectElement : get_options ?

    I'm trying to parse HTML pages with the help of the MSHTML control. I'm using the C++ COM interface. Now I'm at the point where I need to parse the <SELECT> tag. I'm trying to use the method get_options. This function shall return an interface pointer for a collection of OPTION elements in form of an IDispatch interface. I thought I can query an pointer to an IHTMLElementCollection interface from the IDispatch, but it returns NULL.

    So, how can I access the collection?


    Martin

  2. #2
    Join Date
    Dec 2006
    Posts
    1

    Re: IHTMLSelectElement : get_options ?

    You can access the select object as IHTMLElement*. Use get_children on that object to return a collection of HTMLElements and get_innerHTM. This will be the values of the individual options. I could not figure out how to do this any other way. Here is the code excerpt:

    if (strTagName=="SELECT")
    {
    IDispatch* pOptionsDisp2;
    pElem3->get_children(&pOptionsDisp2);

    IHTMLElementCollection* pElemColl2 = NULL;
    hr = pOptionsDisp2->QueryInterface(IID_IHTMLElementCollection,(void **)&pElemColl2);
    if (S_OK==hr)
    {
    long celem2;

    pElemColl2->get_length(&celem2);

    for(int j = 0; j < celem2; j++)
    {
    VARIANT varIndex2;
    varIndex2.vt = VT_UINT;
    varIndex2.lVal = j;

    VARIANT var22;
    VariantInit( &var22 );

    IDispatch* pDisp4;

    HRESULT hr = pElemColl2->item( varIndex2, var22, &pDisp4 );

    if ( hr == S_OK )
    {
    IHTMLElement* pElem4;

    hr = pDisp4->QueryInterface(IID_IHTMLElement,(void **)&pElem4);

    if ( hr == S_OK )
    {
    BSTR bstrTagName4;
    BSTR bstrInnerHTML;
    pElem4->get_tagName(&bstrTagName4);
    pElem4->get_innerHTML(&bstrInnerHTML);
    CString strInnerHTML(bstrInnerHTML);
    CString strTagName4(bstrTagName4);
    ::SysFreeString(bstrTagName4);
    }
    }
    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured